9

我经常从 MacVim 中一次打开整套文件。为此,我通常使用以下命令:

args *PATTERN*
argdo tabedit

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

4

4 回答 4

8

我已经在类似问题中发布了解决方法: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
于 2012-09-19T09:25:23.763 回答
6

像这样的东西应该工作:

:argdo set eventignore-=Syntax | tabedit

Syntaxeventignore设置中删除。

于 2012-09-19T01:38:08.400 回答
2

argdo添加Syntax'eventignore'设置中(请参阅:h argdo)。这意味着您没有对这些文件进行任何突出显示,因为不会为该缓冲区触发语法自动命令事件。这使它看起来像'filetype'没有被设置。这不是真的。您可以通过执行来检查:set ft?。您可以运行:syntax on以重新启用语法突出显示。但这并不是真正可取的,而且感觉很笨拙。

可能更好的方法是让自己摆脱使用制表符,而是使用缓冲区和相关的缓冲区命令。Arglist 相关的缓冲区命令是::next、、、和。您可以打开特定文件或在新拆分中打开缓冲区。:previous:first:last:b file.c:sb file.c

我意识到这是一颗难以下咽的药丸,当然有时您可能真的希望每个缓冲区都放在自己的标签页中。一旦你强迫自己更多地使用缓冲区,你会发现很少需要制表符。您可能想查看 Drew Neil关于如何使用选项卡的出色Vimcast。我还建议使用 Tim Pope 的unimpaired.vim来更轻松地在参数列表中移动。

如果您真的必须在自己的选项卡中使用每个文件,:argdo tabe那么您可能应该在它后面加上一个:syntax on:tabdo doautocmd Syntax

如需更多帮助,请参阅:

:h :argdo
:h arglist
:h buffers
:h :b
:h :sb
:h :next
:h :tabdo
:h :doa
:h Syntax
:h :syn-on
于 2012-09-18T23:32:58.867 回答
0

我不熟悉,args或者argdo如果您需要在不同的选项卡中打开与模式匹配的文件,您可以使用以下内容:

:next *
:tab ball

:next *使用正确的语法突出显示打开所有匹配该模式的文件,但是:tab ball打开内存中的所有文件,如果您有不需要在选项卡中打开的缓冲区,这可能是一个问题。

于 2012-09-18T22:36:34.573 回答