6

I'm using console vim within a tmux window, therefore occasionally vim doesn't recognize that files have been modified (gvim does it on a focus change AFAIK) and in order to avoid getting inconsistent buffers, I manually ask vim to reload them all using

:bufdo :e

However, after this syntax highlighting is lost in all the buffers. Typing :e in a buffer then restores it again. This seems strange, as I'd suppose that :e behaves the same when given directly and when inside :bufdo. Is there a way how to get around that, to have syntax highlighted buffers after :bufdo :e?

6

What you are experiencing seems to be a feature. From :help bufo:

    Note: While this command is executing, the Syntax
    autocommand event is disabled by adding it to
    'eventignore'.  This considerably speeds up editing
    each buffer.

That being said, you probably should focus on which settings you are using on gVim that you are missing on console Vim, as they should be able to behave in the exact same way. If you really need to reload all the buffers, you should try the :checktime command.

  • AFAIK gVim does an additional check when the window holding a file gets focus. This helps to discover changed files early, as most often they're changed as the result of a user action elsewhere. – Petr Pudlák Oct 22 '15 at 15:11
  • 1
    Thanks for pointing me to :checktime, I found this answer on SO which suggests a solution. – Petr Pudlák Oct 22 '15 at 15:13
  • 1
    @PetrPudlák very few features are restricted to the gui version (mostly font and other display options). It is more likely that you have some option (such as 'autoread') or autocmd (such as FileChangedShellPost), or that the versions of Vim and gVim are different. You can compare the options using :set and autocommands using :au and redirecting the output as explained in this question. – mMontu Oct 22 '15 at 16:59
  • I found it: In :help timestamp (my emphasis): After a shell command is run (:!cmd suspend :read! K) timestamps, file modes and file sizes are compared for all buffers in a window. Vim will run any associated FileChangedShell autocommands or display a warning for any files that have changed. In the GUI this happens when Vim regains input focus. – Petr Pudlák Oct 22 '15 at 17:25
  • @PetrPudlák maybe I missed something, but my understanding is that the same behavior (autocommands or warnings) occurs both on console and GUI; in the GUI the behavior is postponed until it gain focus. – mMontu Oct 22 '15 at 19:08
1
:execute 'bufdo :e' | source $VIMRUNTIME/syntax/syntax.vim
  1. execute is a workaround, so that the command following | is not included in the bufdo
  2. sourcing this file is mentioned in :he :syntax-enable
  • Much simpler would be to instead use :execute 'bufdo :e' | syntax on, no need to source any files. – Ruslan Aug 29 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.