I want to take a visual selection and flip it so that the first line of the selection is on the bottom. From:
<other_stuff>
The
wheels
go
round.
<more_stuff>
Visual select the sentence and then flip:
<other_stuff>
round.
go
wheels
The
<more_stuff>
How to do this simply? I would rather not have to install a plugin to do it.
command! -bar -range=% Reverse <line1>,<line2>g/^/m0|nohl " REVERSE line ordering, and move those lines to the top of the file.
To swap the current line with the next one, type ddp while in command mode.
To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.
While you are inside a visual mode, you can switch to another visual mode by pressing either v , V , or Ctrl-v . For example, if you're in line-wise visual mode and you want to switch to block-wise visual mode, just type Ctrl-v . Try it! This will start visual mode on the same selected area as the last visual mode.
When you make a visual selection Vim automatically makes the bookmarks '<
and '>
at the start and end of the block respectively, so you can do what you want in a couple of ways.
In normal mode: '>dd'<P
As an ex command: :'>d | '<-1 put
NB the bookmarks remain after you exit visual mode, so you do not have to stay in visual mode to use these.
edit:
Oops, I misread the question and thought you only wanted the last line put at the start, but you want the entire block reversed. The simplest solution if you are on a unix system:
:'<,'>!tac
This pipes the lines through the unix 'reverse cat' program.
According to :help 12.4
you can mark the first line with the mt
, move to the last line you want reversed then use the command :'t+1,.g/^/m 't
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With