I would like to move to the start of the line on the command-line mode with Ctrl + a. Right now I have the following setting on my ~/.vimrc, which is effective on insert mode:

inoremap <C-a> <Esc>I
inoremap <C-e> <Esc>A

Of course on the normal mode you can move using 0 and $.

At least on the command-line mode, I can move to the end of the line by Ctrl + e, but is it also possible to move to the start of the line, possibly with Ctrl + a?


In command line mode <C-b> is used to move to the beginning of the line :h c_CTRL-B

So you can use

cnoremap <c-a> <c-b>

Note that I would argue that it is useful to learn to use <c-b>: <c-a> in command line mode insert all of the file names which match the pattern in front of the cursor which can be pretty useful. For example, in my home directory, I can type

:argadd .bash

Then when I type <c-a> the command line will become:

:argadd .bashrc .bash_aliases .bash_aliases_local .bash_history .bash_profile

And I can then edit all of these files.

To keep this feature you can also create the invert mapping:

cnoremap <c-b> <c-a>
  • Thanks for the answer and also the tips! But for me it is more comfortable to make the behavior of <c-a> aligned in all situations, as it is the default shortcut on most editors on macOS. – Blaszard Feb 27 '18 at 10:11
  • @Blaszard I understand that it is also the default behavior of most shells :) – statox Feb 27 '18 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.