Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To make a keyboard shortcut for Info in Zsh?

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?

like image 470
Léo Léopold Hertz 준영 Avatar asked May 07 '09 19:05

Léo Léopold Hertz 준영


People also ask

How do you create a shortcut in terminal?

You can create a keyboard shortcut to open a terminal window, create a new shortcut, press the super key and search for “keyboard” or “shortcut” and launch it. Click on “+” option at the end of the list to create a new keyboard shortcut. Provide the required information, Like Name of the shortcut, command.

How do I create a shortcut to a text box?

Insert a Text boxPress and release ALT, N, and then press X. Press the arrow keys to select the Text box that you want, and then press ENTER. Type the text that you want.

What is Ctrl D in Mac?

Control-D: Delete the character to the right of the insertion point. Or use Fn-Delete. Fn-Delete: Forward delete on keyboards that don't have a Forward Delete key.


1 Answers

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.

like image 95
Ville Laurikari Avatar answered Nov 13 '22 05:11

Ville Laurikari