Matching on directories for vim's autocmd
Generally, vim users use the autocmd
command to set specific options for filetypes. Like, if you want all Ruby files to have the shiftwidth
option set to 2 then you would include an autocmd line like this in your ~/.vimrc
file:
autocmd BufRead *.rb set shiftwidth=2
I wanted to do something a bit different. I wanted to set the color scheme for each file in a directory rather than for a file type, and I tried this:
autocmd BufRead *writing* color shine
Nothing happened.
Via :help autocmd-patterns
I was able to learn that if there isn't a slash char (/
) anywhere in the pattern then it just tries to match on the filename. If a slash is included however, the whole path for that file is matched. All I needed was to add a slash:
autocmd BufRead */writing* color shine
Shine On.
Tweet