jdxe
jdxe

Reputation: 83

VIM set cursor position in Command Line

I would like to the following in Vim:

I have this remap in the .vimrc file

:noremap <C-r> :Ack!  /home/user/somefolder/

This is so I can search in Ack in a predefined path (somefolder), but when I use <C-r> to trigger this, the cursor stays at the end of the path, so then I have to use the arrows to go back to just after Ack! because Ack! expects the search term before the path.

Is there anyway I can configure this remap to put the cursor before the path?, so I can trigger <C-r> and immediately start writing the search term.

Many thanks for any help.

Upvotes: 3

Views: 2376

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172748

That's easy:

:noremap <C-r> :Ack!  /home/user/somefolder/<C-Left><Left>

Just like most command-line mappings are concluded with a <CR> to trigger the command, you can also use cursor movements (this is also handy in insert-mode mappings and abbreviations).

Upvotes: 9

Related Questions