Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Search in Files Short-cut Key


I use vimgrep (or grep) to search in files inside vim, but I see it's quite inconvenient to have to write that every time I want to make search in vim. Any idea on how to make a suitable short-cut key to search in files?

Regards,
Rafid

like image 538
Rafid Avatar asked Nov 14 '10 06:11

Rafid


1 Answers

The following will take you to the command-line, pre-populated with vimgrep if you press F3 in normal mode:

:nmap <F3> :vimgrep<space>

If you always wish to search the current directory, try:

:nmap <F3> :vimgrep // *<left><left><left>

If you want to save even more keypresses, try this to search the current directory for the word under the cursor:

:nmap <F3> :vimgrep /<C-R><C-W>/ *<CR>

Of course, these can be put into your .vimrc file.

Vim's inbuilt help system provides lots of useful information on this subject. See the following sections to explain what I have done:

  • :help :nmap
  • :help c_CTRL-R_CTRL-W
like image 80
Johnsyweb Avatar answered Oct 03 '22 11:10

Johnsyweb