相关文章推荐
爱笑的蜡烛  ·  Importing Tester ...·  3 天前    · 
跑龙套的开水瓶  ·  geopandas ...·  1 年前    · 
奋斗的馒头  ·  Mysql中的group_concat在Pr ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams Get used to using :help . :help / shows help about searching, and the answer to your question appears just a little bit down the page. Chris Morgan Jul 7, 2011 at 8:19

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.

@XavierT. any idea, how i can jump a fixed number of results in search. I mean for example jump to the 10th matching line GP cyborg Nov 11, 2015 at 15:24 @GPcyborg : n like most vim operator can be prefixed with a number to repeat the command. If you type 10n it will move to 10th result (after the initial one). It also works for all motion operator like 3j to go down 3 lines. Xavier T. Nov 12, 2015 at 9:26

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.

And in case it wasn't obvious, n and N take you forward and backward through the * matches once you've pressed * . (Or you can just keep pressing * to go forward or # to go backward, but using those shifted-keys is generally sub-optimal.) Herbert Sitz Jul 7, 2011 at 15:57 @Herbert, actually n and N don't take you "forward" and "backward" resp. As @Xavier noted above, n is next and N is previous . Control of forwards and backwards searching is done by stating the search with either the '/' key and the '?' key or with the '*' key and the '#' key. Rob Wells Jul 8, 2011 at 9:22 I don't think * is that useful... most of the time I'm searching for a fragment of a word (for example, a part of a function name). I don't want to /Func , have it take me to SomeFunc and then press '*' to go to the next instance of SomeFunc when the next instance of Func is in SomeOtherFunc . weberc2 Sep 19, 2013 at 14:50 Even worse, with C++ I find it doesn't go from method invocation to method implementation because /\<foo\> does not match "className::foo()" puk Dec 8, 2013 at 20:12 Typing * is incorrect. I.e. a file aa aaa . Search /aa , you have to matches. On the first match pressing * changes the search term. Bernhard Sep 23, 2014 at 9:32 n isn't 'next' but "repeat last search". So entering ?var will start searching upwards from your current position for 'var'. And 'N' is actually "repeat last search in opposite direction" so for this example that would search downwards for 'var' from current position. Rob Wells Mar 27, 2015 at 17:22

plus, navigating prev/next with N and n .

You can also edit/recall your search history by pulling up the search prompt with / and then cycle with C-p / C-n . Even more useful is q/ , which takes you to a window where you can navigate the search history.

Also for consideration is the all-important 'hlsearch' (type :hls to enable). This makes it much easier to find multiple instances of your pattern. You might even want make your matches extra bright with something like:

hi Search ctermfg=yellow ctermbg=red guifg=...

But then you might go crazy with constant yellow matches all over your screen. So you’ll often find yourself using :noh. This is so common that a mapping is in order:

nmap <leader>z :noh<CR>

I easily remember this one as z since I used to constantly type /zz<CR> (which is a fast-to-type uncommon occurrence) to clear my highlighting. But the :noh mapping is way better.

If you're feeling inspired by q/, you should also play with q:. Both are really handy! (Not really related to this question, though.) – Micah Elliott Sep 4, 2015 at 15:28 Thanks, Micah. I knew about 'q:' already, although I don't use it that much. But 'q/' was entirely missed in my vim education, and I think will get a lot of use. – Stabledog Sep 10, 2015 at 13:18 "When we execute a search, Vim scans forward from the current cursor position,stopping on the first match that it finds. " As Practical Vim points out. – bass chuck Oct 16, 2017 at 4:58

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.