If you find these tutorials useful, Please consider making a donation.

Vim 3
Vim Search

Video 7 - Search pt1

Vim Search, to search for a word press * when you are on the word you want to search for (search forward)
n - search for next occurrence
N - search for next occurrence (backward)

# - Search for the word you are on (backward)
n - search for next occurrence (up)
N - search for next occurrence down

/ - search forward
? - search backward

/c - search case insensitive
/C - search case sensitive

/< > - search for whole word (only)

//* - to search for /* (need to escape special characters)


Video 8 - Search pt2

We look at how to find the last time time the search argument found in the document, and the first time the search argument is found in the document

We then look at a couple of ways to turn off the search highlighting (:set nohlsearch, :nohl, :noh) and to turn it back on using :set hlsearch

We also look at how to turn off the incremental search with :set noincsearch and how to turn that back on with :set incsearch

We also look at how to scroll through previous forward search by pressing the forward slash "/" and the arrow up and arrow down keys, the reverse searches by pressing the question mark "?" and then the arrow up and arrow down keys, and we can even search through the previous commands by pressing the colon ":" and then use the arrow up and arrow down keys. Pressing escape gets me out without resubmitting a search or command.

Lower case "q" then pressing forward slash "/" will open a window of our forward search history, we can use vim standards to change a search values and resubmit it by pressing enter or pressing colon ":" lower case "q" to quit out of it. This also works for backward search (lower case "q" question mark "?") and commands (lower case "q" and colon ":")


Video 9 - Substitute (Search and Replace)

The substitue command is the what Vim uses for Search and Replace.

The command starts with a : then the first line and last line you want to search (with a comma in between), then a lower case "s" for substitute, then the forward slash (for search forward) follow by what you want to search for, another forward slash and what you want to replace it with. The example in the video is:


To search the entire document change the line numbers to a percent symbol:


Other things shown in the video are g for globally, i for case insensitve, and c to confirm each change, making the substitue command look like: