Home > Cygwin, shell tips > Wonderful bindkey : assign anything to any key

Wonderful bindkey : assign anything to any key

February 11th, 2011 Leave a comment Go to comments

I have been working on a laptop a lot recently but it was bugging me that I didn’t have the * key on its own key as you do on a full size keyboard. I realized that I wasn’t using the function keys F1 to F12 at the shell level but didn’t know how to configure. Now my situation is a little complicated as I’m using zsh on cygwin on a Windows 7 PC.

Now I’m used to using bindkey to launch widgets eg control-O to duplicate previous word on the command line , and control-L the hyper-useful suspend current command line entry to allow execution of a single command ie do a quick ls or change a permission etc.
here they are:-

bindkey -M viins ‘^O’ copy-prev-shell-word # copy previous shell word

bindkey ‘^L’ push-line # push current command into a buffer,
These use built-in widgets however the really clever amongst can develop their own.

Anyway I just wanted to reprogram the function keys to output another character or string. I posted a question into the zsh newsgroup and quickly got a reply. I needed the -s option

What you have to do, type the following at your prompt yes actually type Control-V followed by F7

> bindkey -s “^vF7” “ls -l” # replace the ls -l with whatever you like

Now heres the rub, what you actually see generated is (will vary from system to system)
bindkey -s “^[[18~” ‘ls -l’

this is what you must copy and paste into your shell startup file

This is actually simple enough for me to type these from the CLI for a short-term use. Boy am I going to enjoy using bindkey!

Categories: Cygwin, shell tips Tags:
  1. No comments yet.
  1. No trackbacks yet.