Vim:对目录中的文件应用设置 [英] Vim: apply settings on files in directory

查看:23
本文介绍了Vim:对目录中的文件应用设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为当前目录下的所有文件指定 Vim 设置?

How do I specify Vim settings for all files under the current directory?

理想的解决方案是,如果 Vim 在搜索 ~/.vimrc 之前搜索并读取当前目录中的 .vimrc,并将设置应用于整个树.

The ideal solution would be if Vim searched for and read a .vimrc in the current directory before searching for ~/.vimrc, and apply the settings there for the entire tree.

我见过一个插件,但这意味着应用设置不透明,因为它们需要安装插件.相比之下,模式行是透明的,因为无论用户的 vimrc 或特定的 vim 调用如何,模式行设置都将应用于该文件.

I've seen a plugin, but this means the applied settings aren't transparent since they require the plugin to be installed. In contrast, a modeline is transparent since regardless of a user's vimrc or specific vim invocation the modeline settings will be applied for that file.

我尝试的东西是

  • 在工作目录中放置一个 .vimrc
  • :so vimrc 在模式行中.
  • placing a .vimrc in the working directory
  • :so vimrc in the modeline.

我想出于安全原因两者都不起作用.我不需要 vimrc 的全部功能;绑定到模式行可接受的设置就足够了.我的目标是让 vimmer 更容易在项目中采用编码标准.

I suppose both don't work for security reasons. I don't need the full power of a vimrc; being bound to settings acceptable by a modeline would suffice. My goal is to make it easier for vimmers to adopt coding standards in a project.

推荐答案

我是插件方式的倡导者.有几个原因:

  • 模式行特别有限:我们不能设置变量(调整其他 (ft) 插件,比如for-snippet 的大括号应该在换行符上吗?"),或者从它们调用函数(我不为了不限制自己的编码标准,我还根据当前目录设置了要使用的 makefile)
  • DRY:对于模式行,需要在每个文件中重复设置,如果要设置的东西太多或要更改的调整太多,将很快变得难以维护,此外,它将需要使用 模板扩展插件(如果您的项目中有多个 vimmer,则应考虑使用该插件).
  • 并非每个人都使用 vim 进行开发.我不想被其他人的编辑器设置打扰,我为什么要寄生他们的设置?
  • 让 vimmer 安装相同的插件更容易,而不是让他们复制粘贴和维护 .vimrc 中的相同行
  • 设置可以与其他项目文件(cvs/svn/git/whatever)一起保存
  • 每个项目都有一个配置文件真的很容易——通过插件,我有一个全局配置文件,用于整个项目的编码标准,以及每个子项目的特定配置文件(使用哪个makefile,哪个可执行调用,...)
  • Modelines are particularly limited: we can't set variables (that tunes other (ft)plugins, like "should the braces of the for-snippet be on a newline ?"), or call function from them (I don't limit myself to coding standards, I also set the makefile to use depending on the current directory)
  • DRY: with modelines, a setting needs to be repeated in every file, if there are too many things to set or tunings to change, it will quickly become difficult to maintain, moreover, it will require the use of a template-expander plugin (which you should consider if you have several vimmers in your project).
  • Not every one uses vim to develop. I don't want to be bothered by other people editor settings, why should I parasite theirs?
  • It's easier to ask vimmers to install a same plugin, instead of asking them to copy-paste, and maintain, the same lines in their .vimrc
  • The settings can be saved with the other project files (cvs/svn/git/whatever)
  • It's really easy to have a configuration file per project -- with the plugin, I have a global configuration file for the coding standards of the overall project, and specific configuration files for each sub-project (which makefile to use, which executable to call, ...)

顺便说一句,sth 的解决方案可用于 source单个配置文件.这与插件方法非常相似,只是 .vimrc 必须被非全局选项寄生,并且它不能轻松支持多个/共享配置文件.

BTW, sth's solution can be used to source a single configuration file. This is very similar to the plugin approach except the .vimrc has to be parasited with non global options, and it does not support easily multiple/shared configuration files.

这篇关于Vim:对目录中的文件应用设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆