💻
notes
  • Initial page
  • sql
    • date-and-time
    • Ordering Columns
    • Replacing Portions of Text
    • count-rows
    • Changing the Case of Strings
    • Create Excerpts with Substring
    • Transactions
    • removing-data
    • Finding Length of Strings
    • add-row-to-a-table
    • limit-and-paginate-results
    • Concatenating Strings
    • SQL JOINs
    • basic-math
    • updating-rows-in-a-table
    • Subqueries
    • Set Operations
    • SQL Basics Cheatsheet
  • ruby
    • gems
      • Auto use Ruby version with gemset
      • Must Have Gems
      • Create Devise user without any validation
    • rails
      • What are the differences between #where and #find?
  • postgresql
    • Export database dump from Heroku and import to local database
  • glossary
  • vim
    • Edit Recorded Macros
    • Sort Multiple Lines
    • Search and Replace
    • Folding
  • iTerm
  • git
    • Git
  • Command Line Utilities
  • How To Use Notes
  • Terminal Cheatsheet for Mac
Powered by GitBook
On this page

Was this helpful?

  1. vim

Search and Replace

PreviousSort Multiple LinesNextFolding

Last updated 5 years ago

Was this helpful?

Source:

Vim provides the :s (:substitute) command for search and replace. To find each occurrence of 'foo' (in all lines) and replace it with bar:

  • :%s/foo/bar/g

To find each occurrence of 'foo' (in the current line only) and replace it with 'bar':

  • :s/foo/bar/g

To change each 'foo' to 'bar', but ask for confirmation first:

  • :%s/foo/bar/gc

To change only whole words exactly matching 'foo' to 'bar'; ask for confirmation:

  • :%s/\<foo\>/bar/gc

To change each 'foo' (case insensitive due to the i flag) to 'bar'; ask for confirmation:

  • :%s/foo/bar/gci

Wikia.com