views:

118

answers:

1

Zsh has the following keyboard shortcut for Man

Esc-h

I would like to have a similar keyboard shortcut for info such as

Esc-i

How can you make such a keyboard shortcut for Info?

+1  A: 

This should do the trick:

function run_info() { 
  # Prepend "info" to the command line and run it.
  BUFFER="info $BUFFER"
  zle accept-line
}

# Define a widget called "run_info", mapped to our function above.
zle -N run_info

# Bind it to ESC-i.
bindkey "^[i" run_info

Just cut'n paste that into a shell to try it out, and add to your .zshrc for permanent effect.

To paraphrase the code: the general idea is that we first define a widget called "run_info", implemented with a function with the same name. It takes the command line buffer and adds "info " to the beginning. Then it accepts the command line (same as pressing ENTER). Finally, the widget is mapped to the keyboard shortcut.

You can read the zshzle(1) man page for more info on how this stuff works.

Ville Laurikari
Thank you Ville! It works :)
Masi