Adding navigation shortcut keys for vim command line

I may not use the correct terminology, but I am struggling to find a way to add some key bindings to use when navigating the command line in vim.

An example is the following command:

:e /really/long/path/that/I/dont/want/to/reenter

and realizing what I really want :tabe instead of a tab or insert a long regex pattern and detect a typo earlier.

Obviously things like ^ , 0 or b will only be entered as characters, so I would like to add some emacs bindings for command mappings like <Ca> to go to the beginning of the line, <Ce> to move to the end lines, and some others - to move between words (at least those that do not conflict with other useful bindings).

Is it possible?

+6
source share
2 answers

As already mentioned, your specific key bindings already exist:

  • Ctrl-b will lead you to the beginning of the command line and
  • Ctrl-e will take you to the end of the command line.

For complete editing of command line commands, you can turn the vim command line into an editable command buffer to solve such problems, rather than using new key bindings.

At the command prompt, press Ctrl-f to enter the command line buffer. You will be in normal mode and will be able to navigate and edit your command line, as well as interact and edit previous commands in the command history.

In your example, once in the command line buffer, you can simply use 0itab to change e to tabe .

Press Enter in this buffer to execute the command where your cursor is located, and Ctrl-c will exit the command line buffer, dropping you back to the command line.

+13
source

here's how i do it:

 " adding emacs keybindings for command mode cnoremap <ca> <Home> cnoremap <ce> <End> 

Edit:

In the help file :help cmdline I found

 :cnoremap <CA> <Home> :cnoremap <CF> <Right> :cnoremap <CB> <Left> :cnoremap <Esc>b <S-Left> :cnoremap <Esc>f <S-Right> 

the last two are what jump around words - happy jumps

+6
source

Source: https://habr.com/ru/post/918407/


All Articles