Yesterday I came across jedi-vim plugin which provides auto-completion for python. I installed the plugin using pathogen by placing it in bundle directory and it is working fine.

Now, as I have mentioned that this plugin is only for filetype: python so I want to load it only when I open files with .py extensions and not when I open other files like .java, .perl, .sh.

So, how can this be achieved.

I am a vim beginner/noob but I googled before asking and found that this can be achieved using vim ftplugin but I have no idea whatsoever where to place which file.

  • As the writer of jedi and jedi-vim I ask you: why do you want to do this? Oct 19, 2012 at 19:09
  • I was about to ask the same thing about plugins. Probably it is fine with jedi-vim, but I have a couple of really simple plugins which are loaded independently of the file type. But when I get more complex plugin solution for a specific file type(for example jedi-viim) I would like to have only it loaded and prevent the simple plugins from messing around. What I need is more like blacklist of file types per plugin, not a whitelist.
    – egelev
    Jun 16, 2015 at 12:06

3 Answers 3


There are plugin managers for Vim that do this

For your example in vim-plug.

Plug 'davidhalter/jedi-vim', {'for': 'python'}

where the string is the author/name of the github repository. All scripts from vim.org are also rehosted on github via vim-scripts.org under the user vim-scripts


I had the same problem when wanting to conditionally load jedi-vim and using the plugin manager Vundle. Now, after a little research I found out that Vundle will load all of its packages/plugins an run time, and there wasn't much I could do about it.

However, jedi-vim has the possibility of being automatically loaded or not. So I decided to have jedi-vim option set to zero (not loaded automatically) in my ~/.vimrc set to one on my ~/.vim/ftplugin/python.vim file.

This option is:

" supposing this is the .vim/ftplugin/python.vim file let g:jedi#auto_initialization = 1


Especially for complex plugins, the plugin must be written in a way that minimizes its effects on other filetypes. You didn't state why you want to limit the plugin's application to Python files (as long as it doesn't install global mappings that interfere with other mappings, you'd normally not care), but after finding an issue about slow loading time, I suspect it's that.

Until the plugin author provides a fix, you can try moving the plugin/jedi.vim file (and the corresponding jedi_vim.py) one directory up, so that it isn't sourced automatically when Vim starts. When you want to use the plugin, load it via :runtime jedi.vim. Maybe you can even move the files into the ftplugin/ folder; they would then be automatically sourced when a Python file is edited; try it out.

Alternatively, you could completely separate the .vim directories for Python and other development, and use two different aliases to start vim-with-python vs. plain vim:

alias vim-with-python='vim --cmd "set rtp^=~/.vim-with-python" --cmd "set rtp+=~/.vim-with-python/after"'
  • By one directory up you mean moving it from bundle/jedi-vim/plugin to bundle/jedi-vim b'coz this didn't worked. it showed some errors saying undefined variable ...
    – ronnie
    Oct 18, 2012 at 7:58
  • Yes, actually, any directory outside plugin/ is fine, because only those are sourced on startup. But as I said, for complex plugins spread over many files, this may not be so easy; you'd have to reverse-engineer the dependency structure and calling sequence. Oct 18, 2012 at 9:27
  • Try: stackoverflow.com/questions/18581218/…
    – Richard
    Oct 5, 2013 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy