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

Written by Michael Lee 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

Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.