Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

vi

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 $
like image 914
Natan Yellin Avatar asked Aug 25 '11 07:08

Natan Yellin


People also ask

How do I go to normal mode in Vim terminal?

Use ctrl-w N to switch to "terminal-normal mode", which will let you navigate around.

What are the motion commands in normal mode Vim?

Normal mode is where one should spend most of their time while using Vim. Remember, this is what makes Vim different. In normal mode, there are multiple ways to move around an open file. In addition to using the cursor keys to move around, you can use h (left), j (down), k (up), and l (right) to move as well.

When under normal mode in Vim what command moves you to the beginning of the line?

You can use ^ or 0 (Zero) in normal mode to move to the beginning of a line. You can also use Shift i to move and switch to Insert mode.

How do you switch between modes in Vim?

Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.


2 Answers

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.

like image 187
Jeromy Anglim Avatar answered Oct 25 '22 09:10

Jeromy Anglim


in vim's command line mode: <ctrl-w> deletes a word

in normal mode: q: goes to the command history (which can be edited with vim commands)

see :help cmdline-editing and :help cmdline-window for more commands.

like image 38
René Nyffenegger Avatar answered Oct 25 '22 10:10

René Nyffenegger