mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Reverse A Group Of Lines as a vim til.
This commit is contained in:
@@ -286,6 +286,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
- [Repeat The Previous Change](vim/repeat-the-previous-change.md)
|
||||
- [Repeating Characters](vim/repeating-characters.md)
|
||||
- [Replace A Character](vim/replace-a-character.md)
|
||||
- [Reverse A Group Of Lines](vim/reverse-a-group-of-lines.md)
|
||||
- [Scrolling Relative to the Window](vim/scrolling-relative-to-the-window.md)
|
||||
- [Searching For Hex Digits](vim/searching-for-hex-digits.md)
|
||||
- [Set End Of Line Markers](vim/set-end-of-line-markers.md)
|
||||
|
||||
20
vim/reverse-a-group-of-lines.md
Normal file
20
vim/reverse-a-group-of-lines.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Reverse A Group Of Lines
|
||||
|
||||
The following command can be used to reverse the order of all lines in a
|
||||
file by doing a global move on all lines that match the beginning of line
|
||||
character starting at the theoretically 0th character:
|
||||
|
||||
```
|
||||
:g/^/m 0
|
||||
```
|
||||
|
||||
Reversing a range of lines is a little more work. Just as the previous
|
||||
example needs to be anchored against the 0th character, a specific range of
|
||||
lines needs to be anchored at the line just before the range. Thus reversing
|
||||
the lines 5 to 10 requires being anchored at line 4, like so:
|
||||
|
||||
```
|
||||
:4,10g/^/m 4
|
||||
```
|
||||
|
||||
[source](http://superuser.com/questions/189947/how-reverse-selected-lines-order-in-vim#)
|
||||
Reference in New Issue
Block a user