Find and replace, Vim tips

1. Find each occurrence of ‘old’ (in all lines), and replace it with ‘new’.

:%s/old/new/g

2. Find each occurrence of ‘new’ (in the current line only), and replace it with ‘old’.

:s/old/new/g

3. Change each ‘old’ to ‘new’, but ask for confirmation first.

:%s/old/new/gc

4. Change each ‘new’ (case insensitive due to the i flag) to ‘old’; ask for confirmation.

:%s/old/new/gci

5. Change each ‘old’ (case sensitive due to the I flag) to ‘new’; ask for confirmation.

:%s/old/new/gcI

6. How to do a find ‘old’ and replace it with ‘new’ only in lines 10 to 70

:10,70s/old/new/g

Anuncios
A %d blogueros les gusta esto: