I like to do the following in my .vimrc
:
if has('nvim')
let g:base_data_folder = $HOME . '/.nvim'
else
let g:base_data_folder = $HOME . '/.vim'
endif
set backupdir = g:base_data_folder . '/backup'
Unfortunately the last line doesn't work and I get an error on starting Vim / NeoVim.
Any ideas how to get this working?
To concatenate a string in Vim, use the . operator.
In Java, String concatenation forms a new String that is the combination of multiple strings. There are two ways to concatenate strings in Java: By + (String concatenation) operator. By concat() method.
Settings use special syntax. The values you set to them are not really expressions. This gives them the benefit that you don't need quotes or escaping, but they're less flexible when it comes to using with programmatic expressions.
One way to avoid this that's common for other kinds of Vim syntax is the execute
command (:help :execute
):
exe 'set backupdir = ' . g:base_data_folder . '/backup'
That said, for settings, there's a dedicated syntax (:help :let-&
) that I'd recommend instead:
let &backupdir = g:base_data_folder . '/backup'
Basically, this allows settings to be treated as "variables" of sorts. I recommend you read all the docs about "let" to get a better understanding of how this works, for other special cases as well.
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