Search and replace all instances of a string in Vim with a confirmation prompt

Written on December 8, 2017

Vim’s search and replace command is really nice for quickly searching and replacing all instances of a string. But sometimes you need to be a little careful with the replacement process and might need to review the matched string before you replace it.

Thankfully, simply adding a c to the end of the search and replace all command in Vim will provide a confirmation prompt, allowing you to review before replacing. It also gives you the option to skip over an instance or stop the search and replace process altogether.

Search and replace with confirmation animation gif

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share more tips on programming and side projects with you. Sign up and I'll send you my articles straight to your email, you'll also get a free copy of the light themed version of my Git cheat sheet.
Git cheat sheet preview image