1

I've just developed a nice solution for automatically loading external changes made to a file, but I'd like a more obvious notification when autoread changes my buffer.

Is there a way of having a warning text appear (eg coloured red) when autoread triggers, so I can easily notice any changes?

3

One way to create a highlighted message is this:

echohl WarningMsg | echo "Buffer changed!" | echohl None

The first command selects a particular highlight mode for any subsequent echo calls. When echo is called the message will be displayed on the status line with approriate color and/or format (in my case white on yellow text). Don't forget the second echohl to return to regular highlighting.

Now I believe you want to display this when autoread is triggered. I am having success with this autocommand:

autocmd FileChangedShellPost *
  \ echohl WarningMsg | echo "Buffer changed!" | echohl None

I do set autoread in my vimrc, load a file with gvim, load it with another editor and change something, come back to gvim. Voila, I get the highlighted message.

  • That text style is what I'm after... but it's an event, not a script... see the link added to autoread in the question. – Tom Hale Aug 1 '17 at 4:15
  • 1
    @TomHale If you're looking to trigger the message in a way that's tightly coupled with vim autoread I'm not sure what the answer is. I was thinking you could use autocommand with some some subsequent event to accomplish it as I describe. If that's not sufficient I might not be able to help. – B Layer Aug 1 '17 at 4:31
  • You might be able to use event FileChangedShell. :h E321 implies that this event is associated with autoread. – B Layer Aug 1 '17 at 4:39
  • 1
    Actually FileChangedShellPost is working for me. Updating my answer. – B Layer Aug 1 '17 at 4:49

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.