Searching word in vim?

Vim

Vim Problem Overview


I can search word in vim with /word. How can I search only for word, excluding searches for word1 and word2?

Vim Solutions


Solution 1 - Vim

like this:

/\<word\>

\< means beginning of a word, and \> means the end of a word,

Adding @Roe's comment:
VIM provides a shortcut for this. If you already have word on screen and you want to find other instances of it, you can put the cursor on the word and press '*' to search forward in the file or '#' to search backwards.

Solution 2 - Vim

  1. vim filename
  2. press /
  3. type word which you want to search
  4. press Enter

Solution 3 - Vim

If you are working in Ubuntu,follow the steps:

  1. Press / and type word to search
  2. To search in forward press 'SHIFT' key with * key
  3. To search in backward press 'SHIFT' key with # key

Solution 4 - Vim

For basic searching:

  • /pattern - search forward for pattern
  • ?pattern - search backward
  • n - repeat forward search
  • N - repeat backward

Some variables you might want to set:

  • :set ignorecase - case insensitive
  • :set smartcase - use case if any caps used
  • :set incsearch - show match as search

Solution 5 - Vim

Basic search (once you have opened the file in vim) using vim:

-Hit ESC on your computer keyboard

-Hit the forward slash symbol on your keyboard /

-Type the word or symbol you intend to search; for example, to search for the term "rbmq" type /rbmq

-Hit Enter

-Hit n to search forward (moving towards the end of the file) and N to search backward (moving towards the beginning of the file)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkalView Question on Stackoverflow
Solution 1 - VimNathan FellmanView Answer on Stackoverflow
Solution 2 - VimMushirView Answer on Stackoverflow
Solution 3 - VimPriya RView Answer on Stackoverflow
Solution 4 - VimNeeruKSinghView Answer on Stackoverflow
Solution 5 - VimAsifView Answer on Stackoverflow