Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need some vim advice on switching to python3

I'm using Vim as my primary editor/IDE for all of my Django projects. Using YouCompleteMe, syntastic and a couple of other plug-ins. The experience is fantastic.

I've decided to start all new projects with python3 as the world is moving to Py3K. But vim is not playing right with both versions of python.

I'm compiled with both versions of python.

vim --version | grep python
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      +python3/dyn     +vreplace

YouCompleteMe don't support python3 yet. jedi-vim works with both versions but I'm not just getting it right.

Usually without any plugins I can invoke any of py/py3 command. But enabling jedi-vim it automatically calls system python2.

I'm using Vundle as vim plug-in manager.

If you please share your vimrc/other configurations/workarounds to use vim for python3 development (or both versions) that'll very helpful for me.

Thanks.

like image 772
moonstruck Avatar asked Apr 23 '15 21:04

moonstruck


People also ask

How do I know if Vim supports python?

Run :ve[rsion] in command-line mode or run vim --version from Bash. If vim was compiled with Python 3, you'll find -python and +python3 . If vim was compiled with Python 2, you'll find +python and -python3 . If vim was compiled without Python support, you'll find -python and -python3 1.

Can you use VIM for python?

Using Vim as a Python IDE The python-mode project is a Vim plugin with syntax highlighting, breakpoints, PEP8 linting, code completion and many other features you'd expect from an integrated development environment.

How do I create a new python file in Vim?

Write Your Python Script To write in the vim editor, press i to switch to insert mode. Write the best python script in the world. Press esc to leave the editing mode. Write the command :wq to save and quite the vim editor ( w for write and q for quit ).


1 Answers

As other people point out in comments, you don't need to change much in terms of Vim config in order to switch to Python3. What you do need to do is identify plugins that use the embedded Python(s), find out which of them support both Python2 and Python3 and tell them to prefer Python3, and phase out those that only work with Python2.

For the plugins I'm using:

  • gundo: let g:gundo_prefer_python3 = 1
  • jedi: let g:jedi#force_py_version = 3
  • syntastic: let g:syntastic_python_python_exec = 'python3', and install the Python3 versions of all checkers
  • python-mode: let g:pymode_python = 'python3'
  • YouCompleteMe: doesn't work with Python3.

Also, nice to have if you plan to edit VimL files with py and py3 commands: install the excellent SyntaxRange, and add this to after/syntax/vim.vim:

call SyntaxRange#Include('\C\v<py\%(thon)?3?\s+\<\<\s*[A-Z]{3,}\zs$', '\C\v^[A-Z]{3,}$', 'python')

like image 86
lcd047 Avatar answered Sep 30 '22 00:09

lcd047