简体   繁体   English

在 vim 缓冲区中的每一行上运行 vim 命令

[英]Run vim command on every line in a vim buffer

I want to JJ on every line in the current vim buffer.我想JJ当前 vim 缓冲区中的每一行。 As I have very huge file, it is not possible to manually run on every line.因为我有非常大的文件,所以不可能在每一行都手动运行。 How can I tell vim to do this for me?我如何告诉 vim 为我做这件事? Basically I have a file which has data in single column.基本上我有一个单列数据的文件。 I want to convert it to three columns我想将其转换为三列

a
b
c

to:到:

a b c

And another one:还有一个:

:%norm JJ

See :help:normal .请参阅:help:normal

Use Macro and Normal mode command .使用宏和普通模式命令

qqJJq

Recoding JJ commands to qJJ命令重新编码为q

uu

Define q macro.定义q宏。 undo all.全部撤消。

:%norm! @q

apply q to entire document.q应用于整个文档。

PS: I'm not good at english PS:我英语不好

:g/^/join

joins consecutive lines (1+2, 3+4, and so on...) in the entire buffer.连接整个缓冲区中的连续行(1+2、3+4 等等...)。 You can also supply a [range] to the :global command, which here is only used for its intelligent line handling;您还可以为:global命令提供[range] ,这里仅用于其智能行处理; the ^ regular expression pattern matches any line . ^正则表达式模式匹配任何行

To join three consecutive lines, use either要连接三个连续的行,请使用

:g/^/.,.+2join

or或者

:g/^/join|join

(The former may give an error if the total amount of lines isn't divisible by 3; the latter avoids that.) (如果总行数不能被 3 整除,前者可能会出错;后者避免了这种情况。)

All lines to only one line所有行到只有一行

:g/^/1j

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM