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

后端 未结 4 1220
一生所求
一生所求 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:01

    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'

    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.

提交回复
热议问题