10

実行後:bufdo e! 、すべてのファイルのファイルタイプ設定が失わ:set ft=XXXれ、各ファイルで手動で実行する必要があります。

誰かがこの問題を解決する方法を知っていますか?

実行:bufdo set ft=XXXが機能せず、すべてのファイルを同じファイルタイプに設定したくありません。

乾杯。

4

3 に答える 3

17

このbufdoコマンドは、パフォーマンス上の理由から、構文の強調表示を更新しません。

vim ドキュメントから:

注: このコマンドの実行中は、Syntax autocommand イベントを「eventignore」に追加して無効にします。これにより、各バッファの編集が大幅に高速化されます

再実行することで、影響を受けるバッファーの構文の強調表示を更新できます。

:syntax on

于 2012-05-09T10:29:19.820 に答える
7

これは、次の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ネストを追加します。

于 2012-05-09T11:27:57.407 に答える
6

変更されたファイルをチェックしている場合 (たとえば、VCS でブランチを切り替えた後) は、この目的のために設計されており、構文の強調表示の問題がない:checktimeよりも適切なソリューションである可能性があります。:bufdo e!

于 2014-01-24T11:48:39.023 に答える