If I'm in command-line mode in vim, and I have the current command line entered (cursor position shown with |):

:somecommand somefilename.txt|

I'd like to navigate backwards so that the cursor is behind the .:

:somecommand somefilename|.txt

Is there a way I can do this with a single command? In normal mode, I could use bb to move back two words, but it seems that the only keybinding I can find in command line mode that's relevant to words is Shift-Left, and this moves by WORDS, not words (i.e. it ignores all punctuation and only looks at whitespace), so the cursor ends up here:

:somecommand |somefilename.txt

If it's relevant, I would like to use this as part of a mapping, so it doesn't matter if it's a bit fiddly to type.

2 Answers 2


Since you don't mind a mapping, we can use

cnoremap <S-Left> <C-f>bb<C-c>

This remaps <S-Left> to the behavior you described, using <C-f> to switch to edit the command line in normal mode. <C-c> then switches back to command line mode.

For details, refer to :h cmdline-window

  • Great, thanks for the idea. Commented May 29, 2021 at 17:17

I don't think there is a built-in way to do it with bare cmdline accroding to :h cmdline.txt.

But if you are into heavy edit of the command line I suggest to use :<C-f> or q: to open command-line window where you can edit it with 'normal' vim commands.

See :h cmdline-window for details.

  • Thanks, this works. But ugly, but it works! Commented May 29, 2021 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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