Pal
Pal

Reputation: 1039

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

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

Upvotes: 9

Views: 1935

Answers (1)

Happy Green Kid Naps
Happy Green Kid Naps

Reputation: 1673

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.

Upvotes: 21

Related Questions