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

前端之家收集整理的这篇文章主要介绍了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嵌套以正确恢复突出显示组并处理缓冲区重新加载,因为明确要求此问题.

原文链接:https://www.f2er.com/bash/386976.html

猜你在找的Bash相关文章