[英]Vim fugitive autocmd not added
我開始使用 Vim 8 並着手設置 my.vimrc。 我使用vim-plug
安裝了vim-fugitive
。 我可以使用插件提供的命令。 我的問題是我想定義自定義命令作為 git 別名。 我關注了這個問題: https://github.com/tpope/vim-fugitive/issues/72但是當我嘗試使用我的autocmd
調用添加的命令時出現錯誤: not an editor command
。 我知道這可能是插件加載和命令聲明之間的時間問題,但我在vim-plug
加載插件之后編寫了我的autocmd
。 這是我的.vimrc
的摘錄:
" Installing/loading plugins
call plug#begin('~/.vim/plugged')
[...]
Plug 'tpope/vim-fugitive'
call plug#end()
" #########################################################
" #
" # Fugitive
" #
" #########################################################
augroup gitAlias
" Remove all gitAlias command
" Needed because they are added every time otherwise
autocmd!
autocmd User fugitive command! -nargs=0 Gpr :G pull --rebase
augroup END
如果我在 Vim 中運行:command: -nargs=0 Gpr :G pull --rebase
,則自定義命令有效。 也許問題來自autocmd
事件,但我找不到確保該事件存在的方法。
在與 Romainl 討論之后,這些命令現在對我有用。 這可能是命令事件中缺少大寫字母的組合,並且我沒有在正確的位置進行測試。
如果你看這里的代碼: https://github.com/tpope/vim-fugitive/blob/3eb6f316c09553989e59bb3802da100a6fb7c091/plugin/fugitive.vim#L362 。 FugitiveDetect
function 僅在BufNewFile,BufReadPost
事件上調用。 這意味着這些命令僅在編輯現有文件或git
庫中的新文件時可用。 我最初認為該命令始終可用。
感謝羅曼爾的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.