Relative paths in .vimrc

3

2

I'd like to add something like

let coffee_compiler = '~/repos/coffee-script/bin/coffee'

to my .vimrc, but vim won't expand the ~ (obviously since it's not my shell).

How can I make this work without including my username? (I am sharing the vimrc file across multiple hosts, so hard-coding the username is a no-no.)

Attila O.

Posted 2013-06-20T12:30:00.310

Reputation: 1 200

Answers

6

There are two ways to solve this:

The built-in expand() function handles special characters and wildcards like the shell:

let coffee_compiler = expand('~/repos/coffee-script/bin/coffee')

Or, since ~ corresponds to the HOME environment variable, you can concatenate its value:

let coffee_compiler = $HOME . '/repos/coffee-script/bin/coffee'

Ingo Karkat

Posted 2013-06-20T12:30:00.310

Reputation: 19 513

2

You should be able to use $HOME for this:

let coffee_compiler = "$HOME/repos/coffee-script/bin/coffee"

l0b0

Posted 2013-06-20T12:30:00.310

Reputation: 6 306