Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to using arrows when accessing vi command history

Tags:

command

vim

vi

In vi/vim, when you execute commands or searches they get added to a list of previous commands. And, just like in shell, they can be retrieved via the up or down arrow keys. These are very inconvenient, is there any other way to traverse the history without using the arrows keys?

like image 535
puk Avatar asked Oct 26 '11 06:10

puk


People also ask

How do I view vi history?

In vi you hit esc once and then k or n will move you backward or forward through the commands. For emacs and gmacs, use control-p or control-n each time. To view more of your history, type "history", and a list of your most recent commands will be displayed along with numbers.

Do you need arrow keys for vim?

The vim editor is derived from vi. It also utilizes the same hjkl keys to replace the functionality of arrow keys. Among vim users, hjkl keys are preferred and advantageous to use. You never have to leave the first row, allowing you to be speedier while working in vim editor.

How do I use arrow keys in vi editor?

vi does not support arrow keys in insert mode. Use vim. Although your vi may just be a link to vim, it may be configured to behave like the "original" vi and thus disables the arrow keys. Just invoke vim directly.

How do I find previous commands in vim?

Press Ctrl+F in command mode to open the command history window. Then, you can use / , ? , and other search commands. Press Enter to execute a command from the history.


2 Answers

Yes. In normal mode q: opens a vim window with the command history. You can work in it like any other vim buffer. Enter executes a command. q/ and q? do the same for searches.

Also, while you are typing a command, you can press Ctrl-F to open the command-line window and continue editing the command there.

like image 74
Itay Perl Avatar answered Oct 21 '22 13:10

Itay Perl


You can use ctrl-n and ctrl-p in the command line to traverse the history and to move between wild card matches. See :help c_CTRL-N.

like image 36
Greg Sexton Avatar answered Oct 21 '22 14:10

Greg Sexton