Some quick tips on searching in nvim.

To search for a word in the current file:

:/your_word

Uses regex to search for the word in the current file. Use ’n’ to go to the next instance of the word, and ‘N’ to go to the previous.

To search for the word selected in visual mode, press * or #. This will search for the word under the cursor.

Now to find and replace, the %s command is used. For example:

%s/old_word/new_word/g

The g flag is used to replace all instances of the word in the file. If you want to have a confirmation for each replacement, use the c flag:

%s/old_word/new_word/gc

The " register stores the text selected in visual mode. To paste the text into a command, use Ctrl-r followed by ". This way selected text can be used in the find and replace command.

Telescope

With the Telescope plugin, searching in nvim is made easier. To search for a word in the current file, use the grep_string function:

:Telescope current_buffer_fuzzy_find 

This will search for the word under the cursor in the current file. To search for word in your current project, use the live_grep function:

:Telescope live_grep

All commands can be mapped to a keybinding in the init.lua file. For example,

vim.api.nvim_set_keymap('n', '<leader>ff', '<cmd>Telescope current_buffer_fuzzy_find<cr>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>fg', '<cmd>Telescope live_grep<cr>', { noremap = true, silent = true })

Thansk for reading! Hope you don’t loose that section fo code you were looking for ever again! Send a messsage if you have a favoirte search tip in nvim that I missed. 😁

-E