Switch Python Version for Vim & Syntastic

后端 未结 8 1138
忘了有多久
忘了有多久 2020-12-24 05:15

Is it possible to change the python version used by syntastic for syntax checking?

As the Issue https://github.com/scrooloose/syntastic/issues/385 indicates I could

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 05:59

    In spite of all the answers here, I still find the recommendation from the FAQ to be the best. I have added this to my .vimrc so that I can easily switch between python versions.

    function Py2()
      let g:syntastic_python_python_exec = '/usr/local/bin/python2.7'
    endfunction
    
    function Py3()
      let g:syntastic_python_python_exec = '/usr/local/bin/python3.6'
    endfunction
    
    call Py3()   " default to Py3 because I try to use it when possible
    

    With those functions installed, it's easy to switch python version right within vim with :call Py2() or :call Py3() depending on what I need at the moment. No need to exit vim and activate a different virtualenv as the popular answer would have you do.

提交回复
热议问题