created July 30, 2003 · complexity intermediate · author MightyByte · version 5.7
The problem: It's always annoying trying to do a search and replace for identifiers in C when the identifier that you are searching for is a substring of other identifiers or keywords in the program. For instance, let's say you want to search for every place you access the ubiquitous loop variable 'i'. If you do a search, you'll hit all the i's in the "if" and "while" keywords and any other identifiers that contain the letter i.
The solution: Use the "\<" and "\>" in your search. These represent the start and end of words. So, to search for all occurrences of the variable 'i', you would use the following command:
/\<i\>
If you want all identifiers that start with 'i', you use "/\<i" and similarly, for all identifiers ending in 'i', use "/i\>".
If you happen to have an example of the word on screen, you can move the cursor anywhere within the word, then press * to search for the next occurrence of that word. Vim inserts \< and \> automatically. See VimTip1.