Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open vim file with cursor on first search pattern match (similar to line no. with vim +N file)

Tags:

regex

vim

vi

Is there a way I can open vi/vim with a given word ( or regex pattern) to match so that the cursor is on the first matched word ( regex pattern) after opening. Something similar to the line no. option

  vim +line_no file.txt

and I'm looking for something like

    vim /regex/ file.txt

This is helpful when I don't have the line no. handy and I can avoid greping the file to search it quickly

like image 579
Pal Avatar asked Aug 30 '16 16:08

Pal


1 Answers

Add a + to your "something like" and you have your answer -- vim +/regex file.txt is what you are looking for (remember to quote your regex to avoid shell from messing it up).

Check out :help starting.txt for more information.

like image 189
Happy Green Kid Naps Avatar answered Nov 08 '22 16:11

Happy Green Kid Naps