From 43ccfb47329584869f217b11ef61fc5da370c11b Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 11 Nov 2015 20:15:51 -0600 Subject: [PATCH] Add Reverse A Group Of Lines as a vim til. --- README.md | 1 + vim/reverse-a-group-of-lines.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 vim/reverse-a-group-of-lines.md diff --git a/README.md b/README.md index 1b894b5..71831c5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/vim/reverse-a-group-of-lines.md b/vim/reverse-a-group-of-lines.md new file mode 100644 index 0000000..a64d473 --- /dev/null +++ b/vim/reverse-a-group-of-lines.md @@ -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#)