Questo frammento di codice in grado di determinare quale versione di Python noi stai usando e passare ad esso (Python sta per quella versione installata).
if has('python')
command! -nargs=1 Python python <args>
elseif has('python3')
command! -nargs=1 Python python3 <args>
else
echo "Error: Requires Vim compiled with +python or +python3"
finish
endif
Per caricare il codice Python, dobbiamo prima capire la sua posizione (qui sotto la stessa directory dello script Vim):
execute "Python import sys"
execute "Python sys.path.append(r'" . expand("<sfile>:p:h") . "')"
Quindi verificare se il modulo python è disponibile. In caso contrario, ricaricarla:
Python << EOF
if 'yourModuleName' not in sys.modules:
import yourModuleName
else:
import imp
# Reload python module to avoid errors when updating plugin
yourModuleName = imp.reload(yourModuleName)
EOF
due modi per chiamare lo:
1.
" call the whole module
execute "Python yourModuleName"
" call a function from that module
execute "Python yourModuleName.aMethod()"
2.
" Call a method using map
vnoremap <leader> c :Python yourModuleName.aMethod()<cr>
" Call a module or method using Vim function
vnoremap <leader> c :<c-u> <SID>yourFunctionName(visualmode())<cr>
function! s:YourFunctionName(someName)
Python YourFunctionName.aMethod(a:someName)
Python YourFunctionName
endfunction
La risposta breve è no. La risposta più lunga è che puoi astrarre un po 'di esso, testando quale versione di Python è disponibile, impostando una variabile dica 'py' a' python' o 'python3', e poi chiamandola con' exec py. 'print ("EAT ME")' '. Sì, non ho mai detto che fosse bello. – lcd047