“Find next” in vim

有些话、适合烂在心里 提交于 2019-12-02 13:46:51
Xavier T.

It is n for next and N for previous.

And if you use reverse search with ? (e.g ?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.

Rob Wells

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 jumps to the previous instance of the word.

Truly a time saver.

When I was beginning I needed to watch a demo

How to search in VIM

  1. type /
  2. type search term e.g. "var"
  3. press enter
  4. for next instance press n (for previous N)
sam hocevar

Are you looking for the n key?

Jim Deville

Typing n will go to the next match.

Micah Elliott

As discussed, there are several ways to search:

/pattern
?pattern
* (and g*, which I sometimes use in macros)
# (and g#)

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 press ctrl+enter after you press something like "/wordforsearch",then you can find the word "wordforsearch" in the current line.Then press n for next match;Press N for perivous match.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!