tags:

views:

50

answers:

1

Hi,

I use the autochdir option in VIM and I also utilize VIM's built-in Python interface. Is it possible to have the current directory for the built-in Python interpreter follow VIM's autochdir. For example, when I am editing a Python file, VIM's autochdir option puts me in the same directory as the edited file as far as VIM is concerned, but I still have to manually

 :py os.chdir(directory)

from the VIM command line in order to get the Python interpreter to recognize the same directory that VIM has.

Is this possible? I'm using VIM 7.2 on Windows.

+1  A: 

You could try putting in vimrc

autocmd Filetype python py os.chdir(directory)

which means that whenever a python file is read or written, it executes this command.

Nuz
Then, if I switch between open buffers, where each buffer contains a different Python file in a different directory, will it restore the respective directory upon switching?
reckoner
autocmd Bufenter *.py py os.chdir(directory) should run the command whenever you switch a buffer
Nuz
Brilliant! here's the full command for the vimrc autocmd BufRead,BufNewFile,Bufenter *.py py os.chdir(vim.eval("expand('%:p:h')"))
reckoner