I'm trying to use indent size as variable, but it doesn't work.
let indent=4 set tabstop=&indent set softtabstop=&indent set shiftwidth=&indent set expandtab
I tried both
%(&indent) - just guessing, but it still broken.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Most is already in the comments, but to summarize:
let indent=4 let &tabstop=indent let &softtabstop=indent let &shiftwidth=indent set expandtab
If you want to set a setting (like
tabstop) to the value of a variable, you have to Vim script expressions instead of set-expressions. In that case, settings are given with a leading
indent is a Vim script variable so NO
& is needed.
See it as namespaces. The leading
& tells that the following name is from the namespace "Vim settings". Like a leading
$ tells, that the following name is from the namespace "environment variables".
So the following two lines leads to identical results.
set tabstop=4 let &tabstop=4
You could also do:
set tabstop=4 let &softtabstop=&tabstop let &shiftwidth=&tabstop set expandtab
Another way to achieve the same (also NOT recommended in this scenario) is:
let indent=4 execute "set tabstop=" . indent execute "set softtabstop=" . indent execute "set shiftwidth=" . indent set expandtab
If you want to have all tabstop related settings follow each other, it is best to use:
set tabstop=4 " set to specific value here, that you want to use set shiftwidth=0 " follow tabstop setting set softtabstop=-1 " follow shiftwidth setting
That will also work for the vartabfeature (since patch 8.1.542).