In an .vimrc file, is it possible to only execute an autocmd if the file is loaded from a particular directory?
In MacVim, i have a line of code in my .vimrc which automatically cds to the directory that contains the file i am editing – however it causes an error when i access the git files that :Gedit creates (vim package fugitive).
The autocmd is:
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
The error is:
Error detected while processing BufEnter Auto commands for "*":
From :echo expand("%") it is clear that Fugitive creates paths that begin with fugitive:///, so i am trying to figure out how to test if the first 12 characters of a file’s path == fugitive:///
Hmm, I think I’ve misunderstood. Your are changing the directory in the shell, not in Vim, don’t you? In that case, autochdir won’t be enough.
:Geditcreates a temporary file with a funky name:There’s no way your shell is going to
cdto that “directory” because it is not a valid path.However, I have
set autochdirwhich tells vim tocdautomatically to the directory containing the current file. Thanks to that I can see that the temporary file is in:I could use the output of
:pwdtocdthere.