User Tools

Site Tools


vi

vi

Search and replace text in entire document

Replace all occurrences of the word “old” with “new”:

:1,$s/old/new/

Source:Search and replace with vi -- part 1

To replace text with slashes:

:1,$s;/var/backups/;/backup/once/;

To replace all occurrences of the string on the same line add a 'g' as suffix of the command. Example:

:1,$s;/var/backups/;/backup/once/;g

Delete lines matching pattern

:1,$g/lines containing this text will be deleted/d

Source:alvin alexander - A vim pattern search and delete example

vi.txt · Last modified: 2021/07/21 13:21 by bas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki