重新加载缓冲区中的所有文件后文件类型设置丢失 [英] filetype setting lost after reloading all files in buffer
本文介绍了重新加载缓冲区中的所有文件后文件类型设置丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行后:bufdo e!
我所有的文件都丢失了文件类型设置,我必须在每个文件中手动运行 :set ft=XXX
.
After running :bufdo e!
All my files lose their filetype setting and I have to manually run :set ft=XXX
in each file.
有人知道如何解决这个问题吗?
Anyone know how to solve this issue?
运行 :bufdo set ft=XXX
不起作用,我无论如何都不想将所有文件设置为相同的文件类型.
Running :bufdo set ft=XXX
doesn't work and I don't want to set all files to the same filetype at any rate.
干杯.
推荐答案
您可以通过以下 autocmd 自动修复此问题:
You can fix this automatically via the following 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
编辑:添加 autocmd 嵌套以正确恢复高亮组并处理缓冲区重新加载,正如问题明确要求的那样.
Edit: Add autocmd nesting for proper restore of highlight groups and handle buffer reloads, as the question explicitly asked for this.
这篇关于重新加载缓冲区中的所有文件后文件类型设置丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文