加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用argdo打开多个文件时,vim中没有打开语法突出显示

发布时间:2020-12-16 01:31:43 所属栏目:安全 来源:网络整理
导读:我经常从MacVim内部一次打开整套文件.为此,我通常使用命令: args *PATTERN*argdo tabedit 这会将工作目录中与模式匹配的所有文件加载到参数列表中,然后在单独的选项卡中将它们全部打开.执行此操作时,语法突出显示不会自动打开,我必须手动设置它.我怎样才能
我经常从MacVim内部一次打开整套文件.为此,我通常使用命令:
args *PATTERN*
argdo tabedit

这会将工作目录中与模式匹配的所有文件加载到参数列表中,然后在单独的选项卡中将它们全部打开.执行此操作时,语法突出显示不会自动打开,我必须手动设置它.我怎样才能解决这个问题?

我已经 posted a workaround了:bufdo在一个类似的问题;这是一个处理您的用例的扩展版本.解决’eventignore’的自动设置非常棘手,因此它得到了充分的评论:
" Enable syntax highlighting when buffers are displayed in a window through
" :argdo and :bufdo,which disable the Syntax autocmd event to speed up
" processing.
augroup EnableSyntaxHighlighting
    " Filetype processing does happen,so we can detect a buffer initially
    " loaded during :argdo / :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.
    " The following autocmd is triggered twice:
    " 1. During the :...do iteration,where it is inactive,because
    " 'eventignore' includes "Syntax". This speeds up the iteration itself.
    " 2. After the iteration,when the user re-enters a buffer / window that was
    " loaded during the iteration. Here is becomes active and enables syntax
    " highlighting. Since that is done buffer after buffer,the delay doesn't
    " matter so much.
    " Note: When the :...do command itself edits the window (e.g. :argdo
    " tabedit),the BufWinEnter event won't fire and enable the syntax when the
    " window is re-visited. We need to hook into WinEnter,too. Note that for
    " :argdo split,each window only gets syntax highlighting as it is entered.
    " Alternatively,we could directly activate the normally effectless :syntax
    " enable through :set eventignore-=Syntax,but that would also cause the
    " slowdown during the iteration Vim wants to avoid.
    " 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,WinEnter * nested if exists('syntax_on') && ! exists('b:current_syntax') && ! empty(&l:filetype) && index(split(&eventignore,','),'Syntax') == -1 | 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读