Searching for text is a fundamental task in any editor. Vim provides powerful and fast ways to perform a vim search directly from normal mode. Let's explore how to use these search patterns to improve your workflow.
Forward Search
To perform a standard forward vim search, simply press the / key in normal mode, followed by your search term. When you press Enter, Vim will jump to the first occurrence of the term after your cursor.
My pretty file is very pretty.
/pretty
This will find the first "pretty" word after the cursor.
Backward Search
Similarly, you can search backward from your cursor's position. Use the ? key followed by your search term. Vim will find the first occurrence before your cursor.
My pretty file is very pretty.
?pretty
This will find the last "pretty" word in the file first.
Navigating Search Results
Once a search is initiated, you can easily navigate through all the matches in the file.
- Press
nto jump to the next match in the direction of the original search. - Press
Nto jump to the previous match, moving in the opposite direction of the original search.
Effective Vim Lookup
The / and ? commands are the core of any vim lookup operation. Whether you need to find a specific function name, a variable, or just a word, this search mechanism is your primary tool. Mastering this simple vim lookup process is essential for efficient navigation and editing.