vim – 重新加载缓冲区中的所有文件后文件类型设置丢失
发布时间:2020-12-15 18:59:19 所属栏目:安全 来源:网络整理
导读:跑完后:bufdo e! 我的所有文件都丢失了文件类型设置,我必须手动运行:在每个文件中设置ft = XXX. 有谁知道如何解决这个问题? 运行:bufdo set ft = XXX不起作用,我不想以任何速率将所有文件设置为相同的文件类型. 干杯. 您可以通过以下autocmd自动修复此
跑完后: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嵌套以正确恢复突出显示组并处理缓冲区重新加载,因为明确要求此问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读