簡體   English   中英

Vim中的Autocmd不調用該函數

[英]Autocmd in vim not calling the function

" 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 test.py這樣的腳本,它將無法正常工作。 但是,如果我只是打開vim然后執行:e test.py該函數被調用。

您應該使用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$)^[

並稱之為一天。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM