Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vimrc - current working directory

Tags:

vim

latex

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?

like image 206
chadgh Avatar asked Sep 11 '09 18:09

chadgh


3 Answers

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.

like image 182
Randy Morris Avatar answered Oct 19 '22 23:10

Randy Morris


see :he filename-modifiers

:!latex % -output-directory %:h
like image 39
glenn jackman Avatar answered Oct 19 '22 23:10

glenn jackman


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.

like image 23
P Shved Avatar answered Oct 20 '22 00:10

P Shved