How to search in Vim
In Normal mode, type / and the word, then press ↵ to search forward. n goes to the next match and N to the previous one. Use ? instead of / to search backwards.
Find the TODOs
Search for TODO with /TODO and ↵, and delete the line with dd. Then n finds the next one, and . repeats the delete.
This editor needs a keyboard. Read on, and play it at your computer.
| Type | What it does |
|---|---|
/word ↵ | Search forward for word. |
?word ↵ | Search backwards. |
| n / N | Next match / previous match. After a ? search, n keeps going backwards. |
| * / # | Search forward / backwards for the whole word under the cursor. |
/word\c ↵ | Ignore case for this search: \c anywhere in the pattern. \C forces case to match. |
/\<word\> ↵ | Only the whole word, not password or wordy. |
/ ↵ | Search forward for the last pattern again. |
/ then ↑ | Step back through earlier searches (type a few letters first to see only those that start with them). |
:noh ↵ | Clear the highlighting until the next search. |
Case-insensitive search
Searches match case by default, so /todo won't find TODO. For one search, add \c to the pattern: /todo\c. To change it for good, turn on two options together: :set ignorecase smartcase. ignorecase ignores case everywhere; smartcase brings it back as soon as you type a capital letter, so /todo finds every spelling and /Todo finds only Todo. Put set ignorecase smartcase in ~/.vimrc, or vim.opt.ignorecase = true and vim.opt.smartcase = true in Neovim's init.lua. The setting applies to :s patterns too; smartcase doesn't apply to * and #.
Clear the search highlight
With the hlsearch option on, every match stays highlighted after a search. :noh (short for :nohlsearch) and ↵ hides the highlight until your next search; :set nohlsearch turns it off altogether. Neovim has hlsearch on from the start and clears it with Ctrl-l as well. Vim starts with it off; :set hlsearch turns it on.
incsearch is the other display option: it shows the first match while you are still typing the pattern. Neovim has it on, and Vim's defaults.vim turns it on.