say that i have a project which lies in a folder called 'bin', and i want some specific vim configuration automatically loaded when i edit any file inside the project folder. how can i do that?
views:
128answers:
2
+4
A:
I think what you want is an autocommand. Perhaps something like this:
autocmd BufRead,BufNewFile ~/bin/* call SetBinOptions()
function SetBinOptions() {
setlocal number
setlocal nowrap
...
}
If you need to do something complex with the path matching, you can take a slightly different approach, making the decision about whether to apply the options within the function. Suppose you had some regex the path had to match:
autocmd BufRead,BufNewFile * call SetCustomOptions()
function SetCustomOptions() {
if (match(expand("%:p"), /regex/) {
setlocal number
setlocal nowrap
...
}
}
Jefromi
2010-04-02 02:06:29
Good idea, for simple cases. A couple problems that could crop up: if you edit a file in the directory from outside the directory, you're in trouble; and there's no way to use `setlocal` properly in this context if you have multiple buffers/windows/tabs, only some of which are in the target directory.
Jefromi
2010-04-02 02:38:30