Oliver Wolfson
ServicesProjectsContact

Development Services

SaaS apps · AI systems · MVP builds · Technical consulting

Services·Blog
© 2025 O. Wolf. All rights reserved.
webdevelopmentjavascriptProgramming
Search and Replace in Vim - A Quick Guide
Vim is a powerful text editor widely used in Unix-based systems. As a programmer's editor, it offers various methods for efficient search and replace operations. This tutorial explores different techniques for performing search and replace in Vim.
June 19, 2023•O. Wolfson

Introduction Vim is a powerful text editor widely used in Unix-based systems. As a programmer's editor, it offers various methods for efficient search and replace operations. This tutorial explores different techniques for performing search and replace in Vim.

Basic Search and Replace Using Slash and Dot The simplest method involves using the slash (/) and dot (.) characters. By pressing / and entering the search term, we can locate the first occurrence of the word. Using the cgn command, we can delete and replace it. The N key helps us find subsequent occurrences, and the Dot (.) key automatically replaces them.

Search and Replace Using the Substitute Command Vim provides the substitute command, which offers more advanced search and replace functionalities. The command syntax is: :s/<search_phrase>/<replace_phrase>/options. Using this command in normal mode, we can specify the search phrase, the replace phrase, and options such as confirmation (c), case-insensitivity (i), and global replacement (g).

Search and Replace for All Occurrences To replace all occurrences in the entire document, we can use the % symbol with the substitute command. For example, :%s/article/tutorial/g replaces all occurrences of "article" with "tutorial" throughout the file.

Search and Replace with Options We can enhance search and replace operations by adding options to the substitute command. The "i" option enables case-insensitive search, while the "c" option prompts for confirmation before each replacement. These options provide greater control and flexibility during the search and replace process.

Conclusion In this tutorial, we explored two methods for performing search and replace operations in Vim. The slash and dot method is straightforward for basic replacements, while the substitute command offers advanced capabilities. Understanding these techniques empowers users to efficiently edit and manipulate text in Vim.

Tags
#vim find and replace#how to search and replace in vim#vi find and replace#vim substitute command#vim :s command#vim replace word#vim change text#vim global replace#vim replace all#vim regex replace#vim sed equivalent#vim multiline search and replace#vim search and replace regex#vim search with pattern#vim substitute with range#vim command line substitution#vim visual mode replace#vim search and replace in files#vim batch replace#vim vs sed replace#vim replace in multiple files#vimgrep replace#vim using %s to replace