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"?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With