16

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?

28

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
  • 1
    BRILLIANT! I'll be using "messages*", but this is exactly what I wanted. I love it. Thank you so much. – rsaw Jun 28 '12 at 0:59
-1

add a line in ~/.vim/filetype.vim,

au BufNewfile,BufRead messages-* set filetype=messages
  • Thanks for responding chris. Didn't work for me. – rsaw Jun 28 '12 at 1:01
  • chris, did you mean ftdetect.vim? – Stefan Majewsky Sep 12 '12 at 11:57
  • 1
    No, ~/.vim/ftdetect/ is a directory, ~/.vim/filetype.vim, all au BufNewfile,BufRead ... set ft=.. can put in this file. more simple. – stardiviner Sep 12 '12 at 22:43
  • Using that file is not advised. Vim docs say: :help new-filetype "... In any way, it's better not to modify the $VIMRUNTIME/filetype.vim file. It will be overwritten when installing a new version of Vim." – Volker Siegel Apr 15 '15 at 21:23
  • 1
    ~/.vim/ is not $VIMRUNTIME system level. Will not be overwritten by new installed Vim. – stardiviner May 12 '17 at 1:46

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.