vim – 重新加载缓冲区中的所有文件后文件类型设置丢失

跑完后:bufdo e!
我的所有文件都丢失了文件类型设置,我必须手动运行:在每个文件中设置ft = XXX.

有谁知道如何解决这个问题?

运行:bufdo set ft = XXX不起作用,我不想以任何速率将所有文件设置为相同的文件类型.

干杯.

您可以通过以下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嵌套以正确恢复突出显示组并处理缓冲区重新加载,因为明确要求此问题.

相关文章

解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全...
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的...
      vim正则匹配:空行:/^$/  /^[\t]*$/注释...
$select-editorSelectaneditor.Tochangelater,run'sele...
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下...
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置...