Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Find next" in Vim

Tags:

vim

editing

To search forward in Vim for cake, I'd type /cake, but the cursor jumps to the first match when I press return. Is there a Vim command analogous to "find next"?

like image 209
Yktula Avatar asked Jul 07 '11 08:07

Yktula


People also ask

How do I get to next occurrence in vi?

vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return. Type n to go to the next occurrence of the string. Type N to go to the previous occurrence.

How Find Next in Linux?

Press / . Type the search pattern. Press Enter to perform the search. Press n to find the next occurrence or N to find the previous occurrence.

How do I open a next file in vim?

You can say :tabe [filename] to open a file in a new tab. Cycling between tabs is done by clicking on the tab or by the key combinations [n] gt and gT . Graphical Vim even has graphical tabs.

What is CGN in vim?

If you searched for plants, beautiful, plants then vim will search for the next occurrence of plants, beautiful, plants and highlight it. You can combine these. cgn will search for whatever you last searched for, highlight it, and then delete it, and put you in insert mode. Then you can replace the text.


2 Answers

It is n for next and N for previous.

And if you use reverse search with ? (for example, ?cake) instead of /, it is the other way round.

If it is installed on your system, you should try to run vimtutor command from your terminal, which will start a tutorial of the basic Vim commands.

Rob Wells advice about * and # is also very pertinent.

like image 67
Xavier T. Avatar answered Oct 22 '22 15:10

Xavier T.


The most useful shortcut in Vim, IMHO, is the * key.

Put the cursor on a word and hit the * key and you will jump to the next instance of that word.

The # key does the same, but it jumps to the previous instance of the word.

It is truly a time saver.

like image 44
Rob Wells Avatar answered Oct 22 '22 14:10

Rob Wells