4

When I switch to vi mode in shell (bash or ksh) very useful to me shortcuts such as C-p and C-n to go back and forth in command history disappear. I don't want to rely on Up and Down for that. I don't want to add key bindings every time for every shell. I just want to know if there's alternative native Vi mode commands for navigation in history.


Btw, C-l for clearing screen disappear too, is there a default key binding for clearing the screen in Vi mode?

1 Answer 1

4

The default key-bindings for moving up or down in the command history in all shells that I know of that supports Vi key-bindings is k for the previous command and j for the next command.

These are the same as the corresponding movement commands in the Vi editor.

For them to work, you will have to be in "normal" mode, i.e. you have to press Esc once.

To clear the screen, use the command clear.

3
  • Thank you. I assume I can't navigate through history while in insert mode. Commented May 1, 2017 at 13:48
  • 2
    @Chinggis6 In insert mode, the previous and next item in the command line history is bound to the up and down arrow keys (as in "normal" mode). As far as I know, bash does not by default add any other key-mapping for this in Vi insert mode. Commented May 1, 2017 at 13:55
  • You could use Ctrl+[ instead of Esc to switch to normal mode (it works in bash vi mode and in vim by default). I find it a lot quicker then moving to Esc. Commented Apr 25, 2021 at 22:04

You must log in to answer this question.