How to make vim apply /var/log/messages syntax highlighting to any file called “messages” or “messages-*”

syntax highlightingvim

I love vim's colorization of /var/log/messages, but it only works for that – the absolute filename. It doesn't work for older rotations of messages (e.g. /var/log/messages-20120610) or for messages files I get from other systems. How can I tweak this?

Best Answer

When you have the file open, you can run:

:set filetype=messages

To automate this for all files called messages, put the following into ~/.vim/ftdetect/messages.vim:

autocmd BufNewFile,BufReadPost *messages* :set filetype=messages
Related Question