[英]How do I run an autocommand on every filetype but one?
我設置了vim以在每次更改緩沖區和檢查時保存文件。 問題是我使用Netrw並最終保存了Netrw緩沖區。 我可以對除netrw以外的所有文件類型運行自動命令嗎?
您可以在autocmd
使用:if
來防止netrw文件。 例如
autocmd FileType * if &ft != 'netrw' | echo "do something" | endif
但是,這仍然不太正確。 您已停止保存netrw緩沖區,但還有其他不應保存的緩沖區。 我建議檢查'buftype'
並查找以協議開頭的文件,例如foo://
。
" create parent directories
" https://stackoverflow.com/questions/4292733/vim-creating-parent-directories-on-save
function! s:MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
augroup BWCCreateDir
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
augroup END
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.