Commands for vi and vim.
See also:
| Contents |
|---|
Search and Replace
Replace 'foo' with 'bar' throughout the file
:g/foo/s//bar/g
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 occurrence of foo,bar use:
g/foo,bar/s//foo,\rbar/g
Remove DOS ^M linefeeds
To remove annoying DOS linefeeds on a Linux/Unix system, use:
:%s/\r//
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
To break up a really long Java classpath on Linux, substitute <tt>:/</tt> with a linefeed ("\r") then <tt>/</tt>:
:s/:\//\r\//g
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 <<
Files
Insert File
:r <filename>
read in a file, insert after current position
Add Comment