Using normal-mode motions in command-line mode in Vim

Natan Yellin picture Natan Yellin · Aug 25, 2011 · Viewed 14.1k times · Source

Is modal editing possible in command-line mode?

Some examples:

  • After writing !ls ~/foo/bar I want to db to delete bar
  • I executed the above command and now I want to change ls to mv and jump back to $

Answer

Jeromy Anglim picture Jeromy Anglim · Aug 25, 2011

By default you can press Control + f (or otherwise see set cedit) when on the Vim command-line, which opens the command-line window where you can edit the command using normal-mode Vim editing keys. Enter will run the command or Control + c will return you to the standard command-line.

So in your specific example, you could press Control + f on the Vim command-line then db and it would do what you want.

When I have to do more sophisticated editing commands I use the above approach because I'm more familiar with Vim editing keys than I am with the alternatives. I also find the normal-mode vim keys more powerful.

See :help c_ctrl-f for more information.