• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Vi Search and Replace

April 3, 2022 by Ulysses

How to do search and replace in Vim.

Search for “foo” and replace it with “bar” in the current line. Use :s

:s/foo/bar/g

:s/foo/bar/g

Search for “foo” and replace it with “bar” in the entire document. Use :%s

:%s/foo/bar/g

:%s/foo/bar/g

You can also pipe instead of forward slash. Useful if your search contains a /.

:%s|foo/|bar|g

:%s|foo/|bar|g

Filed Under: Linux Tagged With: entire, file, replace, search, vim

Subscribe via email.

  • Home
  • About
  • Archives

Copyright © 2012–2022