微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/vim/386976.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐