David542
David542

Reputation: 110083

Only load a plugin if it 'works'

I have vim installed on two machines -- one with python3.7 and one with python3.4 (on an old server that won't have 3.7 without some work). One of the plugins I have:

call plug#begin('~/.vim/plugged')
    "Plug 'SirVer/ultisnips'
    " ... other plugins
call plug#end()

Literally causes an error on every single keypress on insert mode (and the stacktrace looks like a python error). The plugin itself seems to load fine, but in Insert mode it makes vim unusable, here is a ten second video to show: https://gyazo.com/fafb22850f4b1c8c142c0a71a40d698a.

I'm not sure if I'll be able to figure out how to fix this or if perhaps it just won't work with python3.4. Either way, is there a way where I can only load this plugin if there are no issues? For example, something like, in pseudocode:

if "plugin works in insert mode"
    Plug 'SirVer/ultisnips'
endif

How could this be done?

Update: my current solution is as follows, but it does depend on the existence of python (though, to be noted, I haven't been able to get Plug to work at all without python, so I think this is a safe assumption) --

" UtiliSnips to add code-snippets: https://github.com/SirVer/ultisnips
" For whatever reason, not working/compiling with python version 3.4
if has('python3')
    pyx vim.command('let python_version="%s"' % sys.version[:3])
    if python_version == '3.7'
        Plug 'SirVer/ultisnips'
        Plug 'honza/vim-snippets'
    endif
endif

Upvotes: 1

Views: 143

Answers (1)

Luc Hermitte
Luc Hermitte

Reputation: 32926

There is something strange here. You mix python3 with pyx. pyx is meant to be portable to Python2 & 3. python3 says: "if true, from now on, python2 is no longer available!"

Which means, you have the choice here. If you absolutely wish to bind your current Vim to a python3 interpreter, well... assume it: pythonx related features no longer make any sense. You're in your .vimrc, not in a plugin somebody else may use with a Python2 interpreter. Keep it simple.

if has('python3') && (py3eval('sys.version_info[1]') >= 7)
    " no need for the convoluted <<python3 vim.command>>, pyXeval FTW!
    Plug ......
endif

Upvotes: 1

Related Questions