Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use gvim to edit my tex files and it is the default editor. So I just double click on the tex files to edit them and that opens them with Gvim. However, the working directory for Gvim is always the home directory which is odd since I would expect the working directory to be the one in which the file that I have just double-clicked and opened is present. This causes a lot of inconvenience since I normally want to run commands in that directory in Gvim and I have to manually change it every time. Any suggestions on how I can have Gvim starting in the proper way? Thanks a lot in adcvance.

I have already checked the .gvimrc file and I see nothing suspicious. It just has my font and color settings, that's all.

share|improve this question
1  
You can use set autochdir to always change the directory to the directory of the currently edited file. But this might break some plugins. –  Marco Apr 12 '13 at 20:50
    
This seems to work, can you elaborate on the plugin part (It is important to me because I use the Vim latex-suite). Also, any idea why this is not the default behavior? Thanks. –  Ubuntu_kwr Apr 12 '13 at 21:11
1  
It might work for you, but some plugins might rely on autochdir to be switched off, e.g. minitabexpl (if it's not fixed by now). It's not the default since it breaks vi compatibility and it's not always desired. I personally don't use it because when I type :make I want to run make in the main directory. When autochdir is used, vim changes the directory and vim cannot launch make any longer and the build fails. –  Marco Apr 12 '13 at 21:25
    
My problem arises when I want to edit more files. For example when I want to edit the bib file in another buffer, :edit <bibfile> will not work since I am in the home directory and I'll need to change the directory. Usually I maintain many versions of my tex files as the article progresses and often need to copy/paste chunks of text from the older versions etc... all in the same folder. Anyway, thanks again. –  Ubuntu_kwr Apr 12 '13 at 21:30
1  
Use :Ex to open a file explorer in the directory of the current file. Or create a mapping to be able to switch directory without much effort. This is what I use: nnoremap <silent> <leader>p :cd %:p:h<cr> –  Marco Apr 12 '13 at 21:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.