11

I use the Pathogen plugin for gvim. When configuring I set the following in my vimrc file:

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

filetype on  "force reloading *after* pathogen loaded

Now I'm following this tutorial on Youtube by Martin Brochhaus to set up Vim to be useful for Python coding and he suggests the following:

filetype off
filetype plugin indent on
syntax on 

So currently I have filetype on for pathogen but he is suggesting filetype off. What does this line of code do and how should I configure vimrc so Pathogen and Python are both happy?

whytheq
  • 34,466
  • 65
  • 172
  • 267
  • 1
    Related question: [Why vundle requires filetype off](http://stackoverflow.com/q/14642956). – glts Jul 13 '13 at 13:06
  • This is explained in *great* detail at [`:h filetypes`](http://vimdoc.sourceforge.net/htmldoc/filetype.html#filetypes). – glts Jul 13 '13 at 13:10

3 Answers3

10

The :filetype off is superfluous when immediately followed by :filetype [plugin indent] on (as it turns on filetype detection again, as described at :help filetype-plugin-on); don't blindly trust arbitrary resources on the Internet :-)

You usually want filetype detection (so that a corresponding syntax can be loaded for highlighting (with :syntax on)), and filetype-specific settings (the plugin part), and indentation rules (indent).

The only pitfall with Pathogen is that this should come after the Pathogen initialization, but you've done that right.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 4
    Nope, it isn't strictly superfluous. `:filetype off` does in fact do something quite specific, that is, it executes the `ftoff.vim` in the runtime files and this has real side-effects. For example it undefines an autocommand group which may have been set by a system vimrc. – glts Jul 13 '13 at 13:15
  • @glts Technically correct, but (when run in a .vimrc at startup), the actions in `ftoff.vim` are undone by the `:filetype on`. – Ingo Karkat Jul 13 '13 at 19:02
  • Not only technically, it may have real consequences: I was told that some Linux distros have `filetype on` in the system vimrc. In this situation, if you don't do `filetype off` and `on` again, it won't be possible to add ftdetect scripts in `~/.vim`. Fortunately, pathogen internally does `filetype off` so we don't have to worry about that. – glts Jul 13 '13 at 19:19
10
call pathogen#runtime_append_all_bundles()

is not needed at all: the function is deprecated and not useful anyway.

If you really need to be safe, this is what you should have at the top of your ~/.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

However, I've had the following for quite a while without any noticeable issue:

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

filetype plugin indent on
syntax on
romainl
  • 186,200
  • 21
  • 280
  • 313
  • 5
    Agreed. Note that tpope [has updated](https://github.com/tpope/vim-pathogen/commit/532f0ca7d936f1229b926b73e84012a78c4f9800) the preferred `infect()` invocation, so these days it reads `execute pathogen#infect()`. – glts Jul 13 '13 at 15:03
4

filetype on enables filetype detection. Setting filetype plugin or filetype indent to on will turn on filetype detection if it wasn't already anyway. See :help filetype.

Sam Nicholls
  • 861
  • 4
  • 16
  • ok - seems a bit strange that in that tutorial he suggests `filetype off` - he doesn't say why - what would be the advantage of setting it to off? – whytheq Jul 13 '13 at 13:02
  • @whytheq I know Vundle used to require this setting also as it caused an error when loading (but this was patched in vim). However I run Pathogen with vim myself without this line and haven't come across any trouble. – Sam Nicholls Jul 13 '13 at 13:06