tags:

views:

443

answers:

3

I would like to be able to access the current working directory in my vimrc. For example, I can access the current file by using %.

Specifically, I have the following line in my vimrc: map ,l :!latex %

When it runs everything works fine, except the resulting dvi and other files are stored in my home directory instead of my current working directory.

Any suggestions?

+6  A: 

See :help autochdir. Vim can automatically change the current working directory to the directory where the file you are editing lives.

Otherwise, if you want to do this manually, see :help cd and :help lcd.

Randy Morris
A: 

Most likely, you're running vim from your home directory, so it is the current for him. The latex command, being invoked from vim, also therefore has the home directory as current.

You probably know this, and want just to extract path from the filename and supply it as an argument to -o option of the latex command. Just use the shell capabilities:

:!latex % -output-directory `dirname "%"`

I am not sure that it's -output-directory option, but you get what you asked for--a directory name of the file you're editing.

Pavel Shved
+2  A: 

see :he filename-modifiers

:!latex % -output-directory %:h
glenn jackman