71

I am a long time emacs user learning Vim. Emacs lets me navigate in the mini-buffer (where I issue commands like C-x C-s) using the same navigation keyboard shortcuts as in any other buffer. For example, I can navigate forward one character using C-f, even while in the mini-buffer. I could also use the arrow keys, but they are too far away.

Is there any keyboard shortcut to navigate in Vim's command mode (:), without using the arrow keys -- equivalent to emacs C-f, C-b? Thanks.

Rohit
  • 7,449
  • 9
  • 45
  • 55
  • Possible duplicate of [How can I move around in the Vim command line?](http://stackoverflow.com/questions/2075569/how-can-i-move-around-in-the-vim-command-line) – 200_success Aug 31 '16 at 19:05

5 Answers5

97

Adding to Greg Hewgill's answer, you can use q: to open the command-line window, where you have any Vim editing power at your hand.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
Boldewyn
  • 81,211
  • 44
  • 156
  • 212
  • 5
    When I have learned one thing about Vim, then that you never stop learning some new and amazing feature ;-) – Boldewyn Aug 04 '11 at 07:16
  • 27
    Also if you're already on the command line and you want to keep what you've written and still go into the command-line window, type ctrl-F. Thus ":" should accomplish the same thing as "q:". If it doesn't work, than either 'compatible' is set or you have some other key mapped to the 'cedit' option. See :help q: for more details :) – bhh1988 Jul 18 '12 at 03:40
  • 8
    this command was one on of my most annoying commands. Now it's one of the most useful one :) – Dzung Nguyen Jul 21 '12 at 09:24
  • Why can't I paste the '"%' register when using 'q:' or ':' and I can only using the normal ':' ? – MaikoID Nov 20 '14 at 17:12
  • 4
    Literally spent years being annoyed whenever this would pop up unexpectedly. Now I know what it does and I love it! – Max Coplan Oct 04 '19 at 00:03
  • 2
    To make this default: `nnoremap : q:i` – Rudolf Adamkovič Apr 11 '21 at 15:45
48

Some from the Vim help:

CTRL-B or <Home>
        cursor to beginning of command-line
CTRL-E or <End> 
        cursor to end of command-line
CTRL-H              
<BS>        Delete the character in front of the cursor (see |:fixdel| if
        your <BS> key does not do what you want).
<Del>       Delete the character under the cursor (at end of line:
        character before the cursor).
CTRL-W      Delete the |word| before the cursor.  This depends on the
        'iskeyword' option.
CTRL-U      Remove all characters between the cursor position and
        the beginning of the line.  
Jeet
  • 38,594
  • 7
  • 49
  • 56
35

I have these in my .vimrc

cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
Tassos
  • 3,158
  • 24
  • 29
  • 1
    This makes me so happy. For users with issues bind `` see http://stackoverflow.com/a/27206531/1213041 – cdosborn Apr 22 '15 at 00:38
  • I've found that aligning Vim command-mode and shell bindings, especially if you're using Vi bindings, works well. I'd refine the above great suggestion to avoid overwriting existing useful bindings; for example, `C-f` since that's usefully bound to "edit current line in command-mode in buffer". `^b` in command-mode in Vim is already bound to (Emacs-like) ``, and `^a` clashes with `screen(1)` (and for lots of people, `tmux(1)`). – Ben Fowler Dec 01 '21 at 03:44
11

With the default key bindings, vim does not offer non-arrow-key navigation of the command line editing. However, see :help cmdline-editing for an example of how to use the :cnoremap command to set up alternate key bindings.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
1

I achieved that with <C-p> and <C-n> to navigate previous and next commands respectively.

P.S I'm not making any custom binding like Tassos did.