(Uploaded by JohnBot from a locally edited file) |
(Move categories to tip template) |
||
Line 10: | Line 10: | ||
|version=5.7 |
|version=5.7 |
||
|rating=43/27 |
|rating=43/27 |
||
+ | |category1= |
||
+ | |category2= |
||
}} |
}} |
||
This command will reverse all lines in the current buffer: |
This command will reverse all lines in the current buffer: |
Revision as of 10:59, 24 April 2008
Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
created March 7, 2001 · complexity intermediate · author slimzhao · version 5.7
This command will reverse all lines in the current buffer:
:g/^/m0
1. : start command-line mode.
2. g means you'll take an action through the whole file, generally perform a search.
3. / begins the regular expression.
4. ^ matches the start of a line.
5. the second / ends the regular expression; the rest is an Ex command.
6. m means move (t for copy, d for delete).
7. 0 is the destination line (beginning of buffer).
You can use
:g/regexp/t$
to filter all lines and pick the match line together and copy them to the end of the buffer or
:g/regexp/y A
to put them into a register.
Comments
You can drop the '^' in the regexp, an empty regexp it will match any line, too:
:g//m0
Not correct - an empty regex just matches the same thing as the previous regex, which will not necessarily match all lines.
A more intuitive solution is to use the unix "tac" utility, e.g. to reverse the entire file
:%!tac
Here is how to reverse lines 100-150:
:100-150 g/^/m99