When running gvim
by double clicking with a file in a graphical file manager, like nautilus, the vim instance is called with a strange current directory (seems root sometime, but I am not sure). This has the effect that file name completion (C-x C-f
) is, well, not so useful.
I have a map that solve this:
nnoremap <silent> <F3> :lchdir %:p:h <CR>
so that I can hit F3
and I am done. I was trying to make it happens automatically whenever I start editing, so I tried:
autocmd FileReadPost *.tex :lchdir %:p:h <CR>
and with BufReadPost
too, but it doesn't work.
What am I doing wrong?
Notice: Although set autochdir
is working, it is doing this globally; in the help there is a scary notice:
Note: When this option is on some plugins may not work.
So it would be nice to be able to select for which buffers I want to do it, and not setting it globally.
autochdir
as an answer?autocmd
did not work; what if I'd like to have it enabled only for*.tex
files for example?