vim保存录制的宏并通过脚本以非交互方式应用
是否可以保存录制的vim宏并通过脚本以非交互方式应用该宏 例如,假设我有100个类似的文件,如下所示:vim保存录制的宏并通过脚本以非交互方式应用,vim,Vim,是否可以保存录制的vim宏并通过脚本以非交互方式应用该宏 例如,假设我有100个类似的文件,如下所示: variable number of lines foo(a) some more stuff variable number of lines bar(e) variable number of lines foo(a, b) some more stuff variable number of lines bar(e) ESCqa/foo /) i, bESCj0 V/
variable number of lines
foo(a)
some more stuff
variable number of lines
bar(e)
variable number of lines
foo(a, b)
some more stuff
variable number of lines
bar(e)
ESCqa/foo
/)
i, bESCj0
V/bar
k>ESCq
在vim中,我可以录制并回放宏,以将这些文件更改为如下内容:
variable number of lines
foo(a)
some more stuff
variable number of lines
bar(e)
variable number of lines
foo(a, b)
some more stuff
variable number of lines
bar(e)
ESCqa/foo
/)
i, bESCj0
V/bar
k>ESCq
宏很难阅读,可能是这样的:
variable number of lines
foo(a)
some more stuff
variable number of lines
bar(e)
variable number of lines
foo(a, b)
some more stuff
variable number of lines
bar(e)
ESCqa/foo
/)
i, bESCj0
V/bar
k>ESCq
是否有办法保存该宏并以非交互方式应用它,例如,可以轻松地将其应用于100个文件,而无需在vim中以交互方式打开每个文件
这是我已经尝试过的: 将我的宏保存为
a
,然后编写apply_a.ex
脚本:
norm @a
w
最后是ex target.txt
这不会更改文件内容--似乎无法识别宏
a
。来自:帮助启动
-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim. This is useful if you want
to create a script file to be used with "vim -s" or
":source!". When the "scriptout" file already exists, new
characters are appended. See also |complex-repeat|.
{scriptout} cannot start with a digit.
{not in Vi}
-s {scriptin} The script file "scriptin" is read. The characters in the
file are interpreted as if you had typed them. The same can
be done with the command ":source! {scriptin}". If the end
of the file is reached before the editor exits, further
characters are read from the keyboard. Only works when not
started in Ex mode, see |-s-ex|. See also |complex-repeat|.
{not in Vi}
这就是您需要的吗?来自
:帮助启动
-w {scriptout} All the characters that you type are recorded in the file
"scriptout", until you exit Vim. This is useful if you want
to create a script file to be used with "vim -s" or
":source!". When the "scriptout" file already exists, new
characters are appended. See also |complex-repeat|.
{scriptout} cannot start with a digit.
{not in Vi}
-s {scriptin} The script file "scriptin" is read. The characters in the
file are interpreted as if you had typed them. The same can
be done with the command ":source! {scriptin}". If the end
of the file is reached before the editor exits, further
characters are read from the keyboard. Only works when not
started in Ex mode, see |-s-ex|. See also |complex-repeat|.
{not in Vi}
这就是你需要的吗?'p>很抱歉没有正确格式化,我使用的是android'
你有没有用过“bufdo”或听说过它?
您可以一次打开所有文件,并在宏中记录:bn之类的内容,然后转到下一个。Bufer和结尾:wall,意思是写全部,最后是qall
这里有一个例子:
或者你可以做一些类似的事情:
维姆*
让@a='定义宏,包括:wn'
正常n@a
:qall
其中*表示您需要的所有文件
:wn表示“写入当前缓冲区并进入下一步”
n@a是宏a的n倍
:qall表示所有的缓冲区“很抱歉没有正确格式化,我在安卓系统上”
你有没有用过“bufdo”或听说过它?
您可以一次打开所有文件,并在宏中记录:bn之类的内容,然后转到下一个。Bufer和结尾:wall,意思是写全部,最后是qall
这里有一个例子:
或者你可以做一些类似的事情:
维姆*
让@a='定义宏,包括:wn'
正常n@a
:qall
其中*表示您需要的所有文件
:wn表示“写入当前缓冲区并进入下一步”
n@a是宏a的n倍
:qall表示完全所有缓冲区是否期望没有人实际读取保存的脚本并手动编辑它们?它们包含无法打印的ascii字符,因此修改它们看起来很痛苦。是否期望没有人真正读取保存的脚本并手动编辑它们?它们包含无法打印的ascii字符,因此修改它们看起来很痛苦。