Wednesday, January 23, 2013

Useful VI search and Replace Linux commands


Search word from top to bottom
Search word from bottom to top
Search john or joan
/\< the
Search the, theatre or then
Search the or breathe
/\< the\>
Search the
/\< ¦.\>
Search all words of 4 letters
Search fred but not alfred or frederick
Search fred or joe
Search exactly 4 digits
Find 3 empty lines
:bufdo /searchstr/
Search in all open files


Replace all occurences of old by new in file
Replace all occurences with confirmation
Replace all occurences between lines 2 and 35
Replace all occurences from line 5 to EOF
Replace the begining of each line by hello
Replace the end of each line by Harry
Replace onward by forward, case unsensitive
:%s/ *$//g
Delete all white spaces
Delete all lines containing string
Delete all lines containing which didn’t contain string
Replace the first occurence of Bill by Steve in current line
Replace Bill by Steve in current line
Replace Bill by Steve in all the file
Delete DOS carriage returns (^M)
Transform DOS carriage returns in returns
Delete HTML tags but keeps text
Delete lines which appears twice
Increment number under the cursor
Decrement number under cursor
Change text to Rot13

No comments:

Post a Comment