Skip to content

Search and Replaceλ︎

Search and replace within the current buffer:

Search and replace across a project:

Buffer wideλ︎

g m A uses visual-multi multiple curses to match all instances of the selected text and in-place editing

Normal mode editing tools can be used to replace the text at all cursors simultaneously.

multiple cursors in more detail

Replace all occurances of the current-pattern with the new pattern within the buffer.

:%s/current-pattern/new-pattern/g

Add the c option to confirm each replacement

Further examples of :substitue neovim command

Project wideλ︎

Telescope and :cdo

Space f w to search for a word

Ctrl q opens the quickfix list

Use :cdo command to search and replace in the quickfix list

:cdo %s/current-pattern/new-pattern/g

Including the c option to confirm each replacement (using a noice popup when using Practicalli AstroNvim-config)

Spectre

🌐 Spectre is available via the AstroNvim Community project pack and included in the Practicalli astronvim-config

Space s is the search and replace menu

nvim-spectr

🌐 ripgrep and 🌐 sed are required.

🌐 Spectre

Evaluating :cdo command as a project wide search replace

:cdo command could be used to search and replace within the results of a tool that finds matching patterns across a project

Neovim :help :cdo
EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
                            *:cdo*
:cdo[!] {cmd}       Execute {cmd} in each valid entry in the quickfix list.
            It works like doing this:  
                :cfirst
                :{cmd}
                :cnext
                :{cmd}
                etc.
            When the current file can't be |abandon|ed and the [!]
            is not present, the command fails.
            When going to the next entry fails execution stops.
            The last buffer (or where an error occurred) becomes
            the current buffer.
            {cmd} can contain '|' to concatenate several commands.

            Only valid entries in the quickfix list are used.
            A range can be used to select entries, e.g.:  
                :10,$cdo cmd
            To skip entries 1 to 9.

            Note: While this command is executing, the Syntax
            autocommand event is disabled by adding it to
            'eventignore'.  This considerably speeds up editing
            each buffer.
            Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|,
            |:ldo|, |:cfdo| and |:lfdo|.

                            *:cfdo*
:cfdo[!] {cmd}      Execute {cmd} in each file in the quickfix list.
            It works like doing this:  
                :cfirst
                :{cmd}
                :cnfile
                :{cmd}
                etc.
            Otherwise it works the same as `:cdo`.

                            *:ldo*
:ld[o][!] {cmd}     Execute {cmd} in each valid entry in the location list
            for the current window.
            It works like doing this:  
                :lfirst
                :{cmd}
                :lnext
                :{cmd}
                etc.
            Only valid entries in the location list are used.
            Otherwise it works the same as `:cdo`.

                            *:lfdo*
:lfdo[!] {cmd}      Execute {cmd} in each file in the location list for
            the current window.
            It works like doing this:  
                :lfirst
                :{cmd}
                :lnfile
                :{cmd}
                etc.
            Otherwise it works the same as `:ldo`.