How to flip the lines of a visual selection in vim?

后端 未结 4 1218
一生所求
一生所求 2021-02-18 18:38

I want to take a visual selection and flip it so that the first line of the selection is on the bottom. From:


The
wheels
go
round.


        
4条回答
  •  伪装坚强ぢ
    2021-02-18 19:12

    For those more comfortable with Visual Mode:
    1. Identify the line number above the selection you want flipped using :set nu.
    2. Use Shift-V to highlight selection you want flipped (visual mode).
    3. :g/^/m .

    Note that in visual mode it will automatically show up as :'<,'>g/^/m when you type in the command from 3.

    This command works by moving the selection one line at a time into the line number that you give it. When the second item gets pushed into the line number given, it pushes the first down to line number + 1. Then the third pushes the first and second down and so on until the entire list has been pushed into the single line number resulting in a reverse ordered list.

提交回复
热议问题