How to transpose the contents of lines and columns in a file in Vim?

前端 未结 6 641
既然无缘
既然无缘 2021-02-02 16:49

I know I can use Awk, but I am on a Windows box, and I am making a function for others that may not have Awk. I also know I can write a C program, but I would love not to have s

6条回答
  •  感情败类
    2021-02-02 17:45

    If scripts don't do it for you, you could record the actions to a register (the carriage returns are added for readability):

    qa
    1G0
    xGop
    1G0j
    xGp
    q
    

    This will give you a macro that you could run against the example above, or any 2-line strings of the same length. You only need to know the length of the string so you can iterate the operation the correct number of time

    16@a
    

    A fairly basic solution, but it works.

提交回复
热议问题