Difference between revisions of "Vim quick reference"
From thelinuxwiki
(Pushed from thelinuxwiki.com.) |
|||
| (2 intermediate revisions by one user not shown) | |||
| Line 7: | Line 7: | ||
:%s/foo/bar/g | :%s/foo/bar/g | ||
Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive | Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive | ||
| − | :5,12s/foo/bar/g | + | :5,12s/foo/bar/g |
| + | |||
| + | == copy / paste== | ||
| + | |||
| + | The command ‘Y’ or ‘yy’ copies (yanks) one or more lines. To copy one line, two lines, 10 lines, and all lines to the end of the file, respectively: | ||
| + | Y 2Y | ||
| + | 10Y | ||
| + | yG | ||
| + | |||
| + | |||
| + | == delete blank lines== | ||
| + | :g/^$/d | ||
| + | |||
| + | |||
| + | == delete leading whitespaces == | ||
| + | :%le | ||
[[category:vim]] | [[category:vim]] | ||
Latest revision as of 23:49, 5 May 2014
Contents |
search and replace
Change each 'foo' to 'bar' in the current line
:s/foo/bar/g
Change each 'foo' to 'bar' in all lines
:%s/foo/bar/g
Change each 'foo' to 'bar' for all lines from line 5 to line 12 inclusive
:5,12s/foo/bar/g
copy / paste
The command ‘Y’ or ‘yy’ copies (yanks) one or more lines. To copy one line, two lines, 10 lines, and all lines to the end of the file, respectively:
Y 2Y 10Y yG
delete blank lines
:g/^$/d
delete leading whitespaces
:%le