问题描述
我有一个包含数百个 TTL (TeraTermLanguage) 文件的文件夹.现在我想缩进所有这些文件.
I have a folder containing hundreds of TTL (TeraTermLanguage) files.Now I wanted indent all these files.
我已经为缩进创建了 teraterm.vim,我使用 VIM 打开一个文件并执行 "gg=G" 并且整个文件被正确缩进.
I have created teraterm.vim for indentation and I open a file using VIM and do "gg=G" and whole file gets indented properly.
但是有什么办法可以缩进文件夹中的所有文件.
But is there any way, where I can indent all the files in folder.
我想在壳牌的帮助下做.但是在 VIM 中,我无法将文件缩进命令作为参数传递给 VIM.
I wanted to do with help of Shell. But in VIM I couldnt pass file indent command as the argument to VIM.
请建议我可以对 VIM 中的所有文件进行缩进的最佳方式.
Please suggest which is the best way I can do indentation to all the files in VIM.
推荐答案
比从 bash 命令行编写 vim 脚本更简单的是从 vim 内部使用 vimscript(或者可能是一个更简单的单行脚本,用于从命令编写 vim线).我个人更喜欢将 arg 列表用于所有多文件操作.例如:
Much simpler than scripting vim from the bash command line is to use vimscript from inside of vim (or perhaps a much simpler one-liner for scripting vim from the command line). I personally prefer using the arg list for all multi-file manipulation. For example:
:args ~/src/myproject/**/*.ttl | argdo execute "normal gg=G" | update
args
设置 arglist,使用通配符(**
将匹配当前目录以及子目录)|
让我们在一行上运行多个命令argdo
对每个 arg 运行以下命令(它会吞掉第二个|
)execute
防止normal
吞掉下一个管道.normal
运行以下普通模式命令(您最初使用的是什么)update
与:w
类似,但仅在缓冲区被修改时保存.args
sets the arglist, using wildcards (**
will match the current directory as well as subdirectories)|
lets us run multiple commands on one lineargdo
runs the following commands on each arg (it will swallow up the second|
)execute
preventsnormal
from swallowing up the next pipe.normal
runs the following normal mode commands (what you were working with in the first place)update
is like:w
, but only saves when the buffer is modified.
这个 :args ... |阿尔多... |update
模式对于任何类型的项目范围的文件操作都非常有用(例如通过 %s/foo/bar/ge
搜索和替换或设置统一的 fileformat
或文件编码
).
This :args ... | argdo ... | update
pattern is very useful for any sort of project wide file manipulation (e.g. search and replace via %s/foo/bar/ge
or setting uniform fileformat
or fileencoding
).
(其他人更喜欢使用缓冲区列表和 :bufdo
的类似模式,但是使用 arg 列表我不需要担心关闭当前缓冲区或打开新的 vim 会话.)
(other people prefer a similar pattern using the buffer list and :bufdo
, but with the arg list I don't need to worry about closing current buffers or opening up new vim session.)
这篇关于使用文件夹中的所有文件在 VIM 中缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!