For example, I'd like to set
set tabstop=4
set shiftwidth=4
Is there a way to do something like
set tabstop=4
set shiftwidth=tabstop
so I can set both values by only changing a single number?
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 communityYou can use the let
command instead.
Like so:
let &shiftwidth = &tabstop
The &
specifies that the variable name is a Vim option. You can also do :help let-option
to know more about it:
:let &{option-name} = {expr1}
Set option {option-name} to the result of the
expression {expr1}. A String or Number value is
always converted to the type of the option.
For an option local to a window or buffer the effect
is just like using the |:set| command: both the local
value and the global value are changed.
&l:shiftwidth
to only change the buffer local variable.
Might be a better way but you could always do this:
exec 'set shiftwidth=' . &tabstop
Specifically in this case:
http://vimhelp.appspot.com/options.txt.html#%27softtabstop%27:
When 'sts' is negative, the value of 'shiftwidth' is used.
http://vimhelp.appspot.com/options.txt.html#%27shiftwidth%27
When ['shiftwidth' is] zero the 'ts' value will be used.