Neovim – how to do project-wide find and replace?

preview_player
Показать описание
So you are using Neovim but being able to do something as simple as find and replace across your project seems baffling. I'll show you how I do it. It is quick and efficient, especially if you have Telescope.

Here is what I use: `cfdo %s/stringOne/stringTwo/g | update | bd`

0:00 Introduction
0:36 Once at normal speed (short version)
1:09 Command about to be run
1:50 Explaining what is actually being done
1:56 First, find the strings
2:33 Send the instances to the Quickfix list
3:30 Iterate on the instances with `cfdo`
4:20 The command piping into update and bd
6:00 Conclusion, like, subscribe (please!)
Рекомендации по теме
Комментарии
Автор

I recently learned about `cdo` and I was just wondering `what's the difference between that and cdo?` haha and you just exaplained that in a very easy to understand approach. Thanks!

nikensss
Автор

Thanks, that's very comprehensive.

dominykasbartkus
Автор

Thanks for this video, great tutorial! I didn't know about cfdo, I have been using cdo, but it's time to change that :)

leiswatch
Автор

Thank you! I've been postponing this learning for ages.

adheusrangel
Автор

TIL update command exists. Thanks Ben.

driden
Автор

Hi Ben, I saw your dotfiles repo is empty. Any plans to share your config? Looks clean!

colin
Автор

I tend to use ambr for this kind of thing. Little unix utility written in rust.

vext
Автор

Is location list only for one file? So that is the difference...

Danielo
Автор

does refactor in coc.vim not work in php?

otdvrif
Автор

Why won't you use the LSP rename functionality? You basically use the LSP function to rename and don't have to worry about references that are not part of whatever you are renaming. Meaning if a local object has a similar name inside a function that needs to keep its name it won't change that. And LSP refactor is similar to a regular IDE rename function. I have the following keybinding: `vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, {})` and then you do `:wa` to write to all the buffers

norlock
Автор

I'm one of the devs of nvim-spectre (after inactivity of windwp). It's hard to keep it up. Maybe better people make replace and find without plugins tho. Let spectre rest, lmao.

EpsilonKu
Автор

Cool and all, but typing the search term again is.. not so good

Manmanolo