filetype on或filetype off?

why*_*heq 6 vim pathogen

我使用Pathogen插件gvim.配置时我在我的vimrc文件中设置以下内容:

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

filetype on  "force reloading *after* pathogen loaded
Run Code Online (Sandbox Code Playgroud)

现在我在Martin Brochhaus的Youtube上关注这个教程,设置Vim对Python编码很有用,他建议如下:

filetype off
filetype plugin indent on
syntax on 
Run Code Online (Sandbox Code Playgroud)

所以目前我有filetype on病原体,但他建议filetype off.这行代码做了什么,我应该如何配置,vimrc所以Pathogen和Python都很开心?

Ing*_*kat 8

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

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

病原体的唯一缺陷是这应该病原体初始化之后,但你已经做到了这一点.

  • 不,这不是严格多余的。实际上::filetype off确实做了一些非常具体的事情,也就是说,它在运行时文件中执行了ftoff.vim,这确实有副作用。例如,它未定义可能由系统vimrc设置的自动命令组。 (2认同)

rom*_*inl 8

call pathogen#runtime_append_all_bundles()
Run Code Online (Sandbox Code Playgroud)

根本不需要:该函数已被弃用,无论如何都没有用.

如果你真的需要安全,那么你应该拥有最好的东西~/.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
Run Code Online (Sandbox Code Playgroud)

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

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

filetype plugin indent on
syntax on
Run Code Online (Sandbox Code Playgroud)

  • 同意.请注意,tpope [已更新](https://github.com/tpope/vim-pathogen/commit/532f0ca7d936f1229b926b73e84012a78c4f9800)是首选的`infect()`调用,所以这些天它读取`execute pathogen #infect()`. (4认同)