7

I would like to enable Python auto-completion in Vim so maybe this is a non-issue. This is what I've observed:

First, Virtual Environments provides the ability to assign an interpreter on a per-project basis. The assumption being both Python 2.x AND Python 3.x could potentially be used.

I've installed both python 2.x and python3 - no issues.

While installing Vim via Homebrew, no matter what happens only support support for one interpreter is compiled in:

/usr/local/bin/vim --version
...
  • +python3 -python, or
  • -python3 +python

Q: for the purposes of achieving python auto-completion:

  1. Is this a real problem?
  2. If it is, what's the solution?
todd_dsm
  • 918
  • 1
  • 14
  • 21
  • 1
    If you want autocompletion for both Python 2 and Python 3 it can be an issue. Then again, you might be able to find a plugin that does autocompletion without relying on the embedded Python interpreter. – lcd047 May 25 '15 at 18:47

1 Answers1

16

Vim compiled with both, or with 'dynamic' is only available on Windows versions. Mac/*nix/etc can only use one version of Python.

My way around this was to compile two different vims, one with each Python version, and then create a version check in my .vimrc to be co-compatible with the two of them.

if has('python')
  let g:jedi#force_py_version = 2
  let g:syntastic_python_python_exec = 'python2'
  let g:pymode_python = 'python2'
elseif has('python3')
  let g:jedi#force_py_version = 3
  let g:syntastic_python_python_exec = 'python3'
  let g:pymode_python = 'python3'
else
  let g:loaded_jedi = 1
endif

Modifying this with whatever python-specific plugins or function you have installed, of course.

Cometsong
  • 568
  • 9
  • 21
  • Brilliant; I wish I could give you more than 1 up-vote. Thank you. – todd_dsm May 29 '15 at 15:27
  • 2
    I think this is outdated: it seems, one can compile Vim with both `--enable-pythoninterp=dynamic` and `--enable-python3interp=dynamic` on macOS nowadays. – A S Oct 13 '19 at 06:22
  • @A-S True in the later versions of vim. The snippet I put here is for older versions. I still have it in my base `vim` setup though, as several of the servers I work on only have _oooold_ versions and configurations. Some are still ancient Linux versions as they are production servers and are forbidden from changing. "if it ain't broken, don't fix it" kind of perspective. :| – Cometsong Oct 16 '19 at 14:27