Is it possible to set color for the warning message "Swap file XXX already exists! ..."? I couldn't figure out which highlight group it belongs to.

1 Answer 1


It is a bit surprising: my first guess was that one of ErrorMsg, Question, or WarningMsg would work. Turns out the highlight group you are looking for is MoreMsg, e.g.: :highlight MoreMsg guifg=red

  • Thanks. I added this line to my .vimrc file and found that it only works when you do :e filename inside vim, where filename is already opened in another vim buffer? If I directly do vi filename from shell, the warning message is still in original color? Can you help me understand this behavior?
    – Longwu Ou
    Commented Apr 26, 2020 at 13:49
  • My suspicion is when you edit a file from the command line with vim filename, the swap detection occurs before .vimrc is ready so it shows the message with whatever colors are already loaded. You can see it yourself: try to edit a file that has an associated swap with vim filename. When the message appears press o to open it read-only, now execute :e to reload it and you should see the message with the color you specified in your .vimrc. Even if you try the ColorScheme autocommand event you will see the same behavior. That's why I think color schemes are ready before .vimrc
    – Tae
    Commented Apr 26, 2020 at 14:33
  • Additional comment from OP: "If one uses true color support of vim, the line set termguicolors should come after setting the color scheme (colorscheme XXX), so that the highlights of the warning message "Swap file XXX already exists! ..." is determined by the MoreMsg highlight group of the selected colorscheme." (NOTE: OP proposed this as an edit to the answer, but I rejected it since it's a considerable addendum. I'll leave it to @Tae to decide whether to incorporate that into the answer."
    – filbranden
    Commented Jul 12, 2020 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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