Search
Advanced search and Replace (like VSCode) in Neovim (with `:cdo`)
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:
- Fuzzy find with Telescope or other
- Send it to Quickfix-list with
c-q - Search replace in quickfix:
:cdo s/a02t044/my-replacement/g-
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
-
- Then save all files with
:wa
Case Sensitive
for a case SENSITIVE search/replace
gIcan be used such as:cdo s/a02t044/my-replacement/gI
% sign
Not needed in
:cdobut otherwise we’d use:%s/a02t044/my-replacement/gIfor 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.
 in Neovim (cdo)_1777272022460.webp)
# murren.nvim
GitHub - AckslD/muren.nvim: Multiple replacements in neovim
 in Neovim (cdo)_1777272010569.webp)
see also Recursive search-replace in directory
# Match.nvim
 in Neovim (cdo)_1777271931075.webp)