aspin
aspin

Reputation: 317

Moving around the vim command line

I've been a vim user for a while now and I know how to move around the files, but is there anyway to do so on the editor command line itself (is there a name for that?).

e.g. I typed :vimgerp /sometext/ files/*.js and I realized I spelled :vimgrep incorrectly and I want to just jump to the beginning of that line and fix it. Any other sort of small tips here (jump between words -- neither w,e nor alt+left/right seem to work) also appreciated.

Upvotes: 1

Views: 154

Answers (3)

Lieven Keersmaekers
Lieven Keersmaekers

Reputation: 58441

The easiest method would be to use CTRL-F. This opens your command in the command-line window where you can edit your misspelled command like any other plain text.

from vimhelp

OPEN c_CTRL-F q: q/ q?

There are two ways to open the command-line window:

  1. From Command-line mode, use the key specified with the 'cedit' option. The default is CTRL-F when 'compatible' is not set.

  2. From Normal mode, use the "q:", "q/" or "q?" command. This starts editing an Ex command-line ("q:") or search string ("q/" or
    "q?"). Note that this is not possible while recording is in progress (the "q" stops recording then).

Upvotes: 4

phd
phd

Reputation: 94483

http://vimdoc.sourceforge.net/htmldoc/usr_20.html

<Left>          one character left
<Right>         one character right
<S-Left> or <C-Left>    one word left
<S-Right> or <C-Right>  one word right
CTRL-B or <Home>    to begin of command line
CTRL-E or <End>     to end of command line

Upvotes: 4

Mateus Reis
Mateus Reis

Reputation: 306

It's not the fastest and therefore probably only worth it for long commands, but you could just hit enter on the incorrect command as is, undo any incorrect changes if necessary, then open up your command history with q:, where you can edit it as you like. Enter then runs the command if you have your cursor over it in the command history buffer.

Also, shift+arrow left/right jumps between words in command mode, and you can use home/end to go to the beginning and end.

Upvotes: 0

Related Questions