paint-brush
vim - 0 How to Replace Text in a File With VIMby@artwalker
130 reads

vim - 0 How to Replace Text in a File With VIM

by Ethan WangJanuary 11th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

1. Basic Substitution: Using `:s` to replace the first occurrence of text on the current line. 2. Replacing Text on Specific Lines: Employing line numbers or ranges (e.g., `:90,110s`) to replace text within defined line ranges. 3. Pattern-based substitutions: Using regular expressions with the substitute command.

Company Mentioned

Mention Thumbnail
featured image - vim - 0 How to Replace Text in a File With VIM
Ethan Wang HackerNoon profile picture
  1. Basic Substitution: Using :s to replace the first occurrence of text on the current line. :s/more/less result
  2. Replacing Text on Specific Lines: Employing :s with line numbers or ranges (e.g., :90,110s) to replace text within defined line ranges. 1,5s/a/orange/g result
  3. Global Substitution: Utilizing :s with the g flag (:s/pattern/replacement/g) to replace all occurrences of text on a line or throughout the file. :s/a/banana/g result
  4. Pattern-based Substitution: Using regular expressions with the substitute command. For instance, replacing the first character of each word with its uppercase representation using :%s/^./\u&/g. %s/^./\u&/g result