Created
May 7, 2014 01:41
-
-
Save float1251/fdad4eae7644a5f5eb4e to your computer and use it in GitHub Desktop.
vimscriptでpythonを使用する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def func(): | |
print("test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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