16

For example when editing a big .gitignore file and pasting in a block for a newly added toolset's suggested ignore patterns, I manually looked at each line and typed /\.filetype where filetype is what's on that line, to confirm that this wasn't already represented elsewhere.

I don't plan to use sort -u or uniq because I wish to retain the blocks of ignores organized by toolchain involved.

It occurs to me that there must be an even shorter method of basically highlighting other lines that match this line, or searching for the word at the cursor. Would someone be able to tell me how, or if it is not a feature?

1 Answer 1

23

You can use * in normal mode which will go to the next occurrence of the word under your cursor.

As @Sato pointed it out in the comments * allows to search forward and # is the equivalent to search backward. Once you've pressed * or # you can use the keys n and N to navigate between the matches just like you do after searching with / and ?.

Also if you want to search more terms, an option is to yank what you are looking for and then put it in the search register:

  • / to start the search
  • <C-r>" to insert the search terms you just yanked
  • <CR> to begin the search

Note that this method will affect the content of the unnamed register.

2
  • 2
    On a side note: you can also use # instead of * to search backwards. Sep 22, 2015 at 10:01
  • @SatoKatsura: Right I forgot to mention that, thank for pointing it out.
    – statox
    Sep 22, 2015 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.