duckworthd
duckworthd

Reputation: 15197

Setting Vim Options with Variables

I've a question that should be fairly simple, but I have yet to find a solution for. I'm editing my .vimrc and would like to set an option using results saved in a variable. For example, I would like to aggregate all my temporary files in ~/.vimetc. Here's what I would like to do,

let s:vimetc=$HOME.'/vimetc/'
set backupdir=s:vimetc.'backups/'
set directory=s:vimetc.'vimswap/'
set viewdir=s:vimetc.'vimswap/'

Of course, set doesn't resolve variables so I just end up with the literal |s:vimetc.'backups/'|, not at all what I would like. I tried using &s:vimetc with similar results. Does anyone know how to do this?

Upvotes: 20

Views: 6497

Answers (1)

Andy
Andy

Reputation: 4866

let &backupdir=s:vimetc.'backups/'

http://vimdoc.sourceforge.net/htmldoc/eval.html#:let-option

Upvotes: 32

Related Questions