运行后:bufdo e!
我的所有文件都丢失了文件类型设置,我必须:set ft=XXX
在每个文件中手动运行.
有谁知道如何解决这个问题?
运行:bufdo set ft=XXX
不起作用,我不想以任何速度将所有文件设置为相同的文件类型.
干杯.
Ben*_*enj 16
由于bufdo
性能原因,该命令不会更新语法高亮显示:
来自vim docs:
注意:执行此命令时,通过将其添加到"eventignore"来禁用语法autocommand事件.这大大加快了编辑每个缓冲区的速度
您可以通过重新运行来更新受影响缓冲区的语法突出显示:
:syntax on
您可以通过以下autocmd自动修复此问题:
" Enable syntax highlighting when buffers were loaded through :bufdo, which
" disables the Syntax autocmd event to speed up processing.
augroup EnableSyntaxHighlighting
" Filetype processing does happen, so we can detect a buffer initially
" loaded during :bufdo through a set filetype, but missing b:current_syntax.
" Also don't do this when the user explicitly turned off syntax highlighting
" via :syntax off.
" Note: Must allow nesting of autocmds so that the :syntax enable triggers
" the ColorScheme event. Otherwise, some highlighting groups may not be
" restored properly.
autocmd! BufWinEnter * nested if exists('syntax_on') && ! exists('b:current_syntax') && ! empty(&l:filetype) | syntax enable | endif
" The above does not handle reloading via :bufdo edit!, because the
" b:current_syntax variable is not cleared by that. During the :bufdo,
" 'eventignore' contains "Syntax", so this can be used to detect this
" situation when the file is re-read into the buffer. Due to the
" 'eventignore', an immediate :syntax enable is ignored, but by clearing
" b:current_syntax, the above handler will do this when the reloaded buffer
" is displayed in a window again.
autocmd! BufRead * if exists('syntax_on') && exists('b:current_syntax') && ! empty(&l:filetype) && index(split(&eventignore, ','), 'Syntax') != -1 | unlet! b:current_syntax | endif
augroup END
Run Code Online (Sandbox Code Playgroud)
编辑:添加autocmd嵌套以正确恢复突出显示组并处理缓冲区重新加载,因为明确要求此问题.
如果您正在检查更改的文件(例如在VCS中切换分支后),那么它:checktime
可能是一个比:bufdo e!
它更合适的解决方案- 它是为此目的而设计的,并且没有语法突出显示问题.