Vi Cheat Sheet
From Shrubbery
Contents |
[edit] Search and Replace
[edit] Replace 'foo' with 'bar' throughout the file
:g/foo/s//bar/g
[edit] Break 'foo,bar' with a newline after the comma
In vi you can include a newline in a substitution by using the \r character on Linux.
For example, to put a newline after the comma for every occurrency of foo,bar use:
g/foo,bar/s//foo,\rbar/g
[edit] Remove DOS ^M linefeeds
To remove annoying DOS linefeeds on a Linux/Unix system, use:
:%s/\r//
[edit] Replacing a pattern with linefeeds
To break up really long lines using a pattern, use the appropriate escaped linefeed character or characters ( "\r" on Windows):
:s/;C:/\r/g
[edit] Indents
To indent the current line, use >>
To outdent the current line, use <<
To indent/outdent a bunch of lines, type a number before >> or <<

