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
Related videos on Youtube
Author by
rsaw
Student of life and proud RedHatter. Computer-related interests: linux systems-administration, fedora, bash, python, cryptography
Updated on September 18, 2022Comments
-
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 almost 12 yearsBRILLIANT! I'll be using "messages*", but this is exactly what I wanted. I love it. Thank you so much.
-
rsaw almost 12 yearsThanks for responding chris. Didn't work for me.
-
Stefan Majewsky over 11 yearschris, did you mean
ftdetect.vim
? -
stardiviner over 11 yearsNo,
~/.vim/ftdetect/
is a directory,~/.vim/filetype.vim
, allau BufNewfile,BufRead ... set ft=..
can put in this file. more simple. -
Volker Siegel about 9 yearsUsing 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 almost 7 years
~/.vim/
is not$VIMRUNTIME
system level. Will not be overwritten by new installed Vim.