Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Vim Options with Variables

Tags:

let

vim

set

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?

like image 592
duckworthd Avatar asked Apr 20 '11 21:04

duckworthd


People also ask

How do I set environment variables in vim?

Vim can read and write environment variables within your current shell session. Use a $ prefix to identify an environment variable, as in the following examples. Insert the contents of the PATH environment variable into the buffer: Press i to enter insert mode, press Ctrl-r then =$PATH and press Enter.

What is let G in Vimrc?

l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.

What file in your home directory allows you to customize your Vim environment variables permanently?

If you want to set an environment variable permanently, you will need to put it in a file called “ . bash_profile ”. Note: There is another similar file called the . bashrc file, which does a similar thing, but I recommend using .

How do I see environment variables in vim?

Pressing the wildchar key ( Tab , by default) or Ctrl + D will display all of them.


1 Answers

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

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

like image 143
Andy Avatar answered Oct 05 '22 22:10

Andy