Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for a specified word in the file opened in VI editor

Tags:

vim

editor

Please tell me how to search for a specifig word if the file is opened in VI Editor. I know we can do it by using /word_to_be_search but it will not do the exact search for the word.

Example
/sachin will searches for sachin_server, sachin_client and not only sachin
like image 484
Sachin Chourasiya Avatar asked Dec 16 '09 12:12

Sachin Chourasiya


People also ask

How do I search for a specific word in vi editor?

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return.

How do you search for exact words in Vim?

Text Search Another way to find an exact word is to place the cursor on a word, enter command mode, and type an asterisk to find more occurrences of that word. Again, use n and N to repeat the search.

How do I search for a string in Vim?

Perform a basic search in Vim If you are in insert mode, simply press the 'ESC' key. To perform a basic search of the string or text that you want, move to the beginning of the file and simply press the forward-slash ( / ) key. Then type the search string and press ENTER on the keyboard to start searching.

How do I search for multiple words in vi?

Go to search mode i.e. type '/' and then type \v followed by the words you want to search separated by '|' (pipe). Go to search mode and type the words you want to search separated by '\|'.


2 Answers

Try instead:

/\<word\>

the \< and \> match word boundaries.

like image 171
Nick Dixon Avatar answered Oct 17 '22 09:10

Nick Dixon


/\<sachin\>

\< is the beginning of word, and \> is the end of word marker.

like image 40
Paul Tomblin Avatar answered Oct 17 '22 09:10

Paul Tomblin