2016-11-07 42 views
0
" Python logger-print and vice-versa 

function! SetPrintLogMaps() 
    echom "called" 
    nnoremap <buffer> <Leader>lp "lyy"lp"l5cawprint^[ 
    nnoremap <buffer> <Leader>ll "lyy"lp"lcawself.logger.info(^O$)^[ 
endfunction 

autocmd BufWrite,BufRead *.py :call SetPrintLogMaps() 

我有這個autocmd,所以只有在讀取或寫入python腳本時才設置映射。但是當我打開任何python腳本時,函數沒有被調用。vim中的autocmd沒有調用函數

我剛剛發現,如果我從命令行打開腳本,如 vim test.py它不起作用。 但是,如果我只是打開vim,然後執行:e test.py函數被調用。

回答

1

您應該使用FileType事件:

augroup myPythonStuff 
    autocmd! 
    autocmd FileType python call SetPrintLogMaps() 
augroup END 

更好,把這個~/.vim/after/ftplugin/python.vim

nnoremap <buffer> <leader>lp "lyy"lp"l5cawprint^[ 
nnoremap <buffer> <leader>ll "lyy"lp"lcawself.logger.info(^O$)^[ 

和收工。