“Find next” in Vim

前端 未结 7 1538
野性不改
野性不改 2021-01-29 17:10

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 analogo

7条回答
  •  生来不讨喜
    2021-01-29 17:32

    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 z :noh
    

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

提交回复
热议问题