【问题标题】:filetype on or filetype off?文件类型打开或文件类型关闭?
【发布时间】:2013-07-13 22:56:04
【问题描述】:

我为gvim 使用Pathogen 插件。配置时,我在vimrc 文件中设置了以下内容:

call pathogen#infect()
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()

filetype on  "force reloading *after* pathogen loaded

现在,我正在关注 Martin Brochhaus 的 this tutorial on Youtube,将 Vim 设置为对 Python 编码有用,他提出以下建议:

filetype off
filetype plugin indent on
syntax on 

所以目前我有filetype on 用于病原体,但他建议filetype off。这行代码是做什么的,我应该如何配置vimrc 让 Pathogen 和 Python 都满意?

【问题讨论】:

标签: vim pathogen


【解决方案1】:
call pathogen#runtime_append_all_bundles()

根本不需要:该功能已被弃用并且无论如何都没有用。

如果您真的需要安全,这就是您应该在~/.vimrc 顶部的内容:

" turn filetype detection off and, even if it's not strictly
" necessary, disable loading of indent scripts and filetype plugins
filetype off
filetype plugin indent off

" pathogen runntime injection and help indexing
call pathogen#infect()
call pathogen#helptags()

" turn filetype detection, indent scripts and filetype plugins on
" and syntax highlighting too
filetype plugin indent on
syntax on

但是,我已经有很长一段时间没有任何明显的问题:

call pathogen#infect()
call pathogen#helptags()

filetype plugin indent on
syntax on

【讨论】:

  • 同意。请注意,tpope has updated 是首选的 infect() 调用,所以现在它读取为 execute pathogen#infect()
【解决方案2】:

:filetype off 后面紧跟:filetype [plugin indent] on 是多余的(因为它再次打开文件类型检测,如:help filetype-plugin-on 所述);不要盲目相信互联网上的任意资源:-)

您通常需要文件类型检测(以便可以加载相应的语法以进行突出显示(使用:syntax on))、特定于文件类型的设置(plugin 部分)和缩进规则(indent)。

Pathogen 的唯一缺陷是它应该在 Pathogen 初始化之后进行,但你做对了。

【讨论】:

  • 不,严格来说并不是多余的。 :filetype off 实际上做了一些非常具体的事情,也就是说,它在运行时文件中执行 ftoff.vim,这有真正的副作用。例如,它取消定义可能已由系统 vimrc 设置的自动命令组。
  • @glts 技术上是正确的,但是(在启动时在 .vimrc 中运行时)ftoff.vim 中的操作被 :filetype on 撤消。
  • 不仅在技术上,它还可能产生实际后果:有人告诉我,一些 Linux 发行版在系统 vimrc 中有filetype on。在这种情况下,如果不再次执行filetype offon,将无法在~/.vim 中添加ftdetect 脚本。幸运的是,病原体在内部会 filetype off,所以我们不必担心。
【解决方案3】:

filetype on 启用文件类型检测。 将filetype pluginfiletype indent 设置为on 将打开文件类型检测,如果它还没有的话。见:help filetype

【讨论】:

  • 好的 - 在那个教程中他建议 filetype off 似乎有点奇怪 - 他没有说明原因 - 将其设置为关闭有什么好处?
  • @whytheq 我知道 Vundle 过去也需要此设置,因为它在加载时会导致错误(但这已在 vim 中进行了修补)。但是,我自己用 vim 运行 Pathogen,没有遇到任何问题。
猜你喜欢
  • 2020-01-31
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
  • 2014-05-19
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多