vim is the much-loved text editor when it comes to the command line or the terminal, but it has a learning curve when it comes to performing normal day-to-day operations like find and replace.
Let us take a look at various ways to perform find and replace operation using the:s substitution command,
Find and Replace 1st occurrence in a Line
:/s/sample/example
Find and Replace all occurrences of in a Line
:/s/line/line1/s
Find and Replace All occurrences of in a File
:%s/Say/Hello
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to vi,
- How to add Colors to VIM (syntax highlighting)
- How to perform Find and Replace using vim Editor
- How to update VIM version on a Mac
- How to Select All Text in Vim/Vi editor
- Guide: Install Vim on Mac
- The Vim (vi) Mac Configuration File Details
- Fix :wq! Vi Error - E32: No file name (when write and quit)
- How to Copy all text to Clipboard in Vim
- How to Uninstall Vim on Mac?
More Posts:
- How to Stop Photos App from auto loading when device connected to the Mac - Mac-OS-X
- How to remove Spring Boot Text Banner shown in Console when Application Starts - Java
- Fix Error 2711 SQL RBS client - The installer has encountered an unexpected error. The specified Feature name ('Docs') not found in Feature table - SharePoint
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash] - Linux
- PowerShell: Check if File Exists - Powershell
- bash: cls: command not found - Linux
- Upload docx file using PHP script - PHP
- Fix NVIDIA GeForce Experience ERROR CODE 0x0003 - HowTos