在vim中将垂直文本转换为水平文本



我想将文件中的垂直文本转换为水平文本。像

1  
2  
3    

1 2 3

我可以使用tr命令tr 'n' ' ' <file 来完成此操作

但我想使用vim

选择行并将它们与J连接。

来自:h J:

                            *J*
J           Join [count] lines, with a minimum of two lines.
            Remove the indent and insert up to two spaces (see
            below).
                            *v_J*
{Visual}J       Join the highlighted lines, with a minimum of two
            lines.  Remove the indent and insert up to two spaces
            (see below).  {not in Vi}

一个简单的。使用从第一行到最后一行的范围,并在它们之间留一个空格:

:0,$join

而且,只是为了好玩:

:{fromLine},{toLine}!tr 'n' ' '

另一种方式:用替换n

:{fromLine},{toLine}s/n/ /g

最新更新