3

I am learning vim recently as i have to use vim in some restricted machines. As i am a vscode user, I would like to find ctrl+f and ctrl+shift+f equivalent to do string search

Ctrl+f will search within the file

ctrl+shift+f  will search in all the files in the folder tree.

I added ripgrep , It search :Rg! ,it always search in all files like Ctrl+shift+f Whether Rg can be used to search with the files? (like ctrl+f).

Also how to add ctrl+f and ctrl+shift+f mapping in vim

Axifive
  • 1,159
  • 2
  • 19
  • 31
Samselvaprabu
  • 16,830
  • 32
  • 144
  • 230
  • 2
    Vim can do both things out of the box without adding plugins and external dependencies. If you are going to use Vim for some time, I suggest learning how to use it (with `:help user-manual`) rather than trying to replicate your VSCode workflow. – romainl Oct 22 '20 at 05:20

2 Answers2

2

I agree with romainl, vim already has these function without any plugins. Just want to add some details.

Search string in current file is done by / in normal mode, see :h /, :h pattern.txt.

Search string in many files may be done by vimgrep command, see :h :vimgrep.

Also you may find useful vim fzf plugin, it uses ripgrep you already installed and does much more.

Of course you can do mappings on Ctrl-F and Ctrl-Shift-F, but it will override builtin vim command, so I don't recommend to do it.

map <C-F> /
map <CS-F> :vimgrep /

See :h map.txt

Dmitry
  • 436
  • 2
  • 7
0

To add on what @Dmitry stated in their answer (regardless of whether or not one should), while you can map Ctrl-F to search, vim doesn't support detection of Ctrl vs Ctrl-Shift keybinds so an alternative would have to be used. One such alternative would be using Ctrl-Alt-F instead:

map <C-f> /
map <C-M-f> :vimgrep /

Or (for compatibility depending on how your terminal treats the Alt key):

map <C-f> /
map <Esc><C-f> :vimgrep /

Edit: Thanks to @Baczek for mentioning in a comment, there's an answer here that shares how to achieve such 'impossible' mappings in some contexts (I haven't tested its solutions myself).

  • See https://unix.stackexchange.com/questions/631241/mapping-otherwise-conflicting-or-unmappable-keys-in-terminal-vim for options on how to make the impossible sort of possible. – Baczek Mar 25 '23 at 11:16