我希望vim在打開或創建文件時打開:Explorer。例如。當我撥打vim
沒有任何選擇。Vim自動命令在打開「nothing」時觸發
調用vim newfile.txt
應該仍然表現正常的方式。
我該怎麼做呢?我似乎無法找到正確的autocmd
。
我希望vim在打開或創建文件時打開:Explorer。例如。當我撥打vim
沒有任何選擇。Vim自動命令在打開「nothing」時觸發
調用vim newfile.txt
應該仍然表現正常的方式。
我該怎麼做呢?我似乎無法找到正確的autocmd
。
如果你想只VIM調用做到這一點,最好的辦法是使用argc()
:
autocmd VimEnter * :if argc() is 0 | Explore | endif
argc()
函數返回一個數字上的命令行中指定的文件名時,VIM被調用,除非有修改參數列表,更多信息請點擊:h argc()
。
找到自己的答案:
"open to Explorer when no file is opened
function! TabIsEmpty()
" Remember which window we're in at the moment
let initial_win_num = winnr()
let win_count = 0
" Add the length of the file name on to count:
" this will be 0 if there is no file name
windo let win_count += len(expand('%'))
" Go back to the initial window
exe initial_win_num . "wincmd w"
" Check count
if win_count == 0
" Tab page is empty
return 1
else
return 0
endif
endfunction
" Test it like this:
" echo TabIsEmpty()
function! OpenExplorer()
if (TabIsEmpty())
:Explore
end
endfunction
這段代碼的最大部分是由this question拍攝。