Perhaps I'm not using the right terminology, but I'm struggling to try to find a way to add some key bindings for use while navigating the command line in vim.
An example would be the following command:
:e /really/long/path/that/I/dont/want/to/reenter
and realizing that I actually want to :tabe
instead of tab, or entering a long regex pattern and discovering a typo earlier in it.
Obviously things like ^
, 0
or b
would just be entered as characters, so what I'd like to do is add a few emacs bindings for command mappings such as <C-a>
to move to the beginning of the line, <C-e>
to move to the end of the line and some others to move between words (at least those that don't conflict with other useful bindings).
Is this possible?
As others have mentioned, your specific keybindings already exist:
For the full command-line editing experience you can turn the vim command-line into an editable command buffer to address issues like this, rather than using new key bindings.
While typing in the command-line, hit Ctrl-f to enter the command-line buffer. You'll be in normal mode and can navigate around and edit your command line, as well as interact with and edit previous commands in your command history.
In your example, once in the command-line buffer, you could simply use 0itab
to change e
to tabe
.
Hit Enter in this buffer to execute the command that your cursor is on, and Ctrl-c will exit the command-line buffer, dropping you back onto the command-line.
here is how I would do it:
" adding emacs keybindings for command mode
cnoremap <c-a> <Home>
cnoremap <c-e> <End>
In the help file :help cmdline
I found
:cnoremap <C-A> <Home>
:cnoremap <C-F> <Right>
:cnoremap <C-B> <Left>
:cnoremap <Esc>b <S-Left>
:cnoremap <Esc>f <S-Right>
the last two are the ones for jumping around words - happy jumping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With