You seem to have a bug in your filename glob pattern. The one you showed:
*/logs/couchdb/{,.log}{,.[0-9]*,-[0-9]*}
It will indeed match files inside a logs/couchdb/
directory, but the last part will only match files named .log
or .789
or -789
or .log.789
or .log-789
. Yes, these are full filenames, only filenames starting with .
or -
are valid. If you want to match any files with a log extension, you need to use *.log
instead. You can then add the second part to also include numbered log files.
So, for example, it seems to me this would work:
*/logs/couchdb/*.log{,.[0-9]*,-[0-9]*}
This would match test.log
or test.log.789
or test.log-789
.
Or, you might want to just keep it simple and match on the directory name, match any filename, regardless of extension:
*/logs/couchdb/*
I can't really explain why you're getting a filetype of messages
on that test.log
, since that second pattern isn't really matching that filename either... So I can't really explain it. You might want to use :verbose set filetype?
to understand where it's being set (it will list the rule where it's coming from, with the file and line, so you can easily find it.)
Assuming the pattern with the proper *
wildcard for the filename solves your issue, there are a couple other things you might want to consider.
First, instead of modifying file /usr/share/vim/vim80/filetype.vim
of your Vim installation, create a new user-local file for your user instead.
Create a directory ~/.vim/ftdetect
. Inside it, create ~/.vim/ftdetect/couch_log.vim
with the single line:
au BufNewFile,BufRead */logs/couchdb/*.log{,.[0-9]*,-[0-9]*} set filetype=couch_log
If you really want this configuration to be sustem-wide, you can do the same with a ftdetect
directory under $VIMRUNTIME
(probably somewhere under /usr/share/vim
in your system, check :echo $VIMRUNTIME
to find out exactly where.)
The main advantage of not modifying a system file is that you won't lose the setting if you upgrade or reinstall Vim on that machine, which would probably overwrite the file you modified. Also, by keeping it inside your .vim
, it's easy to take that with you to a different machine, since you can transport all your configurations together from a single ~/.vim
directory.
You don't need to create an augroup
for this rule, Vim does that automatically for you as it sources *.vim
files from the ftdetect
directory.
Finally, you'll probably want to use set filetype=couch_log
, rather than setf couch_log
, in your filetype detection override.
The reason for it is that set filetype=couch_log
will always set the filetype unconditionally, even if the file name has already matched another pattern and has been assigned a filetype in a previous rule. setf couch_log
, on the other hand, will only set the filetype if one wasn't set yet. So you might end up skipping the setting if the file previously matched another filename pattern and was assigned a filetype already.
Since you're writing your overrides, you'll probably want to always use the stronger set filetype=...
, since you probably want your rule to "win" in case a file matches multiple rules.
See :help ftdetect
, it has more details on Vim's handling of the ftdetect
directory and also spells out the differences between set filetype
and setf
.
:verbose set ft
? – Maxim Kim Nov 21 '19 at 10:15filetype=messages Last set from ~/.vimrc
So it looks like it's not looking in the file that I've set up... – Chapo Nov 22 '19 at 1:17set nocp
andfiletype plugin on
should have been in your vimrc – Maxim Kim Nov 22 '19 at 4:21:setf
, but instead rather use:set filetype=
– Christian Brabandt Nov 22 '19 at 7:31