Skip to content

Instantly share code, notes, and snippets.

@float1251
Created May 7, 2014 01:41
Show Gist options
  • Save float1251/fdad4eae7644a5f5eb4e to your computer and use it in GitHub Desktop.
Save float1251/fdad4eae7644a5f5eb4e to your computer and use it in GitHub Desktop.
vimscriptでpythonを使用する
def func():
print("test")
" VimScriptのサンプル
" Pythonインターフェイスを使用
" インデントに注意
function! Test()
python3 <<EOM
print("Hoge")
EOM
endfunction
"もちろんライブラリも使える
function! Test2()
python3 <<EOM
import functools
a = functools.reduce(lambda x, y: x+y,[1, 2, 3, 4, 5])
print(a)
EOM
endfunction
" 外部ファイルを読み込んで実行するようにしてみる
" このvimスクリプトと同じ階層にpytestというファイルを作成する
function! Test3()
python3 <<EOM
import pytest
pytest.func()
EOM
endfunction
"pathを追加
let path = expand("%:p:h")
python3 <<EOM
import vim, sys
sys.path.append(vim.eval("path"))
EOM
call Test()
call Test2()
call Test3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment