4. Vim Search Patterns

Lesson Content

To search for an expression just type the / key and then your search result while you are in a vim session. Once you hit enter, you can press “n” to go forward or “N” to go backward in your search results.

My pretty file is very pretty.

/pretty

will find the pretty words in the text file.

The ? search command will search the text file backwards, so in the previous example, the last pretty would come up first.

My pretty file is very pretty.

?pretty

will find the pretty words in the text file.

Exercise

Play with the search key, open a text file in vim with: vim [textfile] and start searching!

Quiz Question

# What key is used to search in vim? > It is possible to find the current word the cursor is currently on. Open up a file in normal mode. Put the cursor on a word, then press * to find the next occurrence and # for the previous occurrence. On the bottom left corner, we can see the word that is being searched. 1. [ ] \? 2. [ ] \< 3. [ ] \\ 4. [x] \/