MacVim 内からファイル セット全体を一度に開くことがよくあります。これを行うには、通常、次のコマンドを使用します。
args *PATTERN*
argdo tabedit
これにより、パターンに一致する作業ディレクトリ内のすべてのファイルが引数リストにロードされ、それらすべてが個別のタブで開かれます。これを行うと、構文の強調表示が自動的にオンにならず、手動で設定する必要があります。どうすればこれを修正できますか?
MacVim 内からファイル セット全体を一度に開くことがよくあります。これを行うには、通常、次のコマンドを使用します。
args *PATTERN*
argdo tabedit
これにより、パターンに一致する作業ディレクトリ内のすべてのファイルが引数リストにロードされ、それらすべてが個別のタブで開かれます。これを行うと、構文の強調表示が自動的にオンにならず、手動で設定する必要があります。どうすればこれを修正できますか?
同様の質問の回避策をすでに投稿していました。: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
このようなものが動作するはずです:
:argdo set eventignore-=Syntax | tabedit
Syntax
それは設定から削除されeventignore
ます。
argdo
を設定に追加Syntax
し'eventignore'
ます( を参照:h argdo
)。これは、そのバッファに対して Syntax autocommand イベントが発生しないため、これらのファイルが強調表示されないことを意味します。が設定されていないように見えます'filetype'
。本当じゃない。を実行することで確認できます:set ft?
。を実行:syntax on
して、構文の強調表示をオンに戻すことができます。しかし、これは本当に望ましいことではありません。
おそらくより良いアプローチは、タブの使用をやめ、代わりにバッファーと関連するバッファー コマンドを使用することです。Arglist 関連のバッファ コマンドは:next
、 、:previous
、:first
、および:last
です。:b file.c
またはを使用して特定のファイルを:sb file.c
開き、新しい分割でバッファを開くことができます。
これは飲み込むのが難しい薬であることを認識しています。確かに、各バッファを独自のタブページに入れたい場合があります。バッファをより多く使用するように強制すると、タブの必要性がほとんどないことがわかります。How to use tabsに関する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
args
orには詳しくありませんargdo
が、パターンに一致するファイルを別のタブで開く必要がある場合は、次のようなものを使用できます。
:next *
:tab ball
:next *
正しい構文の強調表示でパターンに一致するすべてのファイル:tab ball
を開きますが、メモリ内のすべてのファイルを開きます。これは、タブで開く必要のないバッファーがある場合に問題になる可能性があります。