Search

Search IconIcon to open search

Advanced search and Replace (like VSCode) in Neovim (with `:cdo`)

Last updatedUpdated: by Simon Späti · CreatedCreated:

Search replace is a key need in IDEs, but Neovim does it a bit different than usual editors. That’s why I created below notes for myself to solve the same with :cdo and QuickFix lists.

It works great. But there are also community plugins that do it more visual, see second part.

# Build in with Commands and Quickfix List

Search replace in project:

  1. Fuzzy find with Telescope or other
  2. Send it to Quickfix-list with c-q
  3. Search replace in quickfix: :cdo s/a02t044/my-replacement/g
    1. if you leave the search pattern empty in :s //replace/ it will use the content of the / register, which you fuzzy finder can set. improvement suggested

  4. Then save all files with :wa

Case Sensitive

for a case SENSITIVE search/replace gI can be used such as :cdo s/a02t044/my-replacement/gI

% sign

Not needed in :cdo but otherwise we’d use :%s/a02t044/my-replacement/gI for replacement in the whole file, not just current line. As cdo goes through all lines by line, it works there

# VS Code like Searche Plugins

# With Nvim-spectre and Add-on Code

Developing Search & Replace (similar to VS Code) with nvim-spectre : r/neovim

Hey there! I wanted to bring the search and replace functionality of Visual Studio Code (VSC) to Neovim. To make this possible, I’m using the internal functions of  nvim-spectre and my own plugin,  NuiComponents. The plugin will allow you to create custom layouts, forms, and other components (hopefully, it will be prepared for publishing at any time soon).

You can find the search and replace implementation  here.

# murren.nvim

GitHub - AckslD/muren.nvim: Multiple replacements in neovim

see also Recursive search-replace in directory

# Match.nvim

GitHub - ankushbhagats/match.nvim: A minimal Neovim plugin for floating search & replace with live match tracking, navigation, and quick replacements. · GitHub


Origin: Neovim, VSCode