使用文件夹中的所有文件缩进VIM [英] Indenting in VIM with all the files in Folder
问题描述
我有一个包含数百个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.
我想在Shell的帮助下做.但是在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 ... | argdo ... | update
模式对于任何类型的项目范围文件操作(例如,通过%s/foo/bar/ge
搜索和替换或设置统一的fileformat
或fileencoding
)非常有用.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!