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?
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.
l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.
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 .
Pressing the wildchar key ( Tab , by default) or Ctrl + D will display all of them.
let &backupdir=s:vimetc.'backups/'
http://vimdoc.sourceforge.net/htmldoc/eval.html#:let-option
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With