IT Questions and Answers :)

animated-update-image-0026

COVID-19 India HEAT MAP

A message to our readers about COVID-19

With the uncertainty surrounding the outbreak of the corona virus. We want to reassure our reader stay safe and Healthy.Be aware and alert. Work as one nation. Sanitize and disinfect all equipment before entering your home, work and anywhere.

Thursday, November 23, 2017

Using VIM, what is the find\replace function for replacing the word 'hot' with 'cold' in an entire document?

Using VIM, what is the find\replace function for replacing the word 'hot' with 'cold' in an entire document?

  • :s/hot/cold/g
  • :%s/hot/cold/g
  • :qw! hot\cold
  • :w!/hot/cold%s 
Using VIM, what is the find\replace function for replacing the word 'hot' with 'cold' in an entire document?

 EXPLANATION

Vim provides the :s (substitute) command for search and replace.  The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:
:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
:s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
:%s/\<foo\>/bar/gc
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.

SOURCE

http://vim.wikia.com/wiki/Search_and_replace
Share:

0 comments:

Post a Comment

Popular Posts