Skip to main content

vim or vi searching for whole words or string

Search for a whole word or string in VI or VIM, can be done easily and a time savee so no need to keep pressing next or 'n' for the next match.

How to search for a whole word or string in VI or VIM?

Example open a file with a list of IP addresses.

vim list-of-local-ips.txt

Example contents:
192.168.13.130
192.168.13.131
192.168.13.1
192.168.13.135
192.168.13.137
192.168.13.23
192.168.13.13
192.168.13.100

If vi or vim is insert mode, press ESC until it's in command mode,

If need to search for 192.168.13.1, or just 13.1

In comand-line mode type: 
:/\<13.1\>
and press enter 

Or see picture below:
After pressing enter it will go directly to 192.168.13.1,  if /13.1 is type then it will match also 192.168.13.135, 192.168.13.131 etc..

But with the /\<word or string\> syntax it will find the whole word.


That's it, explore vi/vim for time saver tips. Cheers!




Lift up your needs in Prayer; with a humble and contrite heart. God listens to the broken hearted. Don't carry the burden alone, for it is written, come to me who are weary and burden and I will give you rest.

Comments