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

12,304

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
Share:
12,304

Related videos on Youtube

rsaw
Author by

rsaw

Student of life and proud RedHatter. Computer-related interests: linux systems-administration, fedora, bash, python, cryptography

Updated on September 18, 2022

Comments

  • rsaw
    rsaw over 1 year

    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?

  • rsaw
    rsaw almost 12 years
    BRILLIANT! I'll be using "messages*", but this is exactly what I wanted. I love it. Thank you so much.
  • rsaw
    rsaw almost 12 years
    Thanks for responding chris. Didn't work for me.
  • Stefan Majewsky
    Stefan Majewsky over 11 years
    chris, did you mean ftdetect.vim?
  • stardiviner
    stardiviner over 11 years
    No, ~/.vim/ftdetect/ is a directory, ~/.vim/filetype.vim, all au BufNewfile,BufRead ... set ft=.. can put in this file. more simple.
  • Volker Siegel
    Volker Siegel about 9 years
    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."
  • stardiviner
    stardiviner almost 7 years
    ~/.vim/ is not $VIMRUNTIME system level. Will not be overwritten by new installed Vim.