tags:

views:

41

answers:

2

I am trying to figure out how I can define an autocmd that influences all files under a specific path.

The autocmd I have tried is something like

autocmd BufNewFile,BufRead /specificPath/** imap <buffer> ....

Now, I'd expect this autocmd to be used if I edited, say, /foo/bar/specificPath/baz/something/bla.txt, but not if I edited /foo/bar/here/and/there/moreBla.txt

If I start vim being in a directory 'above' specificPath, this works as I want it. But it doesn't if I am below that directory. Obviously, the autocmd's pattern is matched against the relative file name, not the absolute one.

+1  A: 

So, I've done this in my code with paths under a particular path. You need to do:

autocmd BufRead,BufNewFile */somepath/* set filetype=sometype

At least, that's what I was using to set a given filetype for things under a particular library path. Hopefully that will help with your example.

AlBlue
That was stupid of me, I should have thought about the asterik in front of the pattern...
René Nyffenegger
what if I wanna give absolute paths and not part of a path ?like `/home/user/work/` will there be a preceding asterisk?
jeffjose
I think there's a way of doing that too - just miss out the leading * in the list. You probably need the leading / if you want to match somethng like /home, though.
AlBlue
A: 

This will answer all your questions. : )

:h autocmd-patterns

RymdPung