How to do whole-word search similar to “grep -w” in Vim

后端 未结 3 642
青春惊慌失措
青春惊慌失措 2020-12-13 05:54

How do I do a whole-word search like grep -w in Vim, which returns only lines where the sought-for string is a whole word and not part of a larger word?

3条回答
  •  余生分开走
    2020-12-13 06:37

    \
    

    matches bar but neither foobar nor barbaz nor foobarbaz.

    Use it like this in a substitution:

    :s/\/baz
    

    Use it like this to list all the lines containing the whole word bar:

    :g/\
    

    :h pattern is a good read.

提交回复
热议问题