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?

3 Answers 3


You 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.
  • 2
    Note that you'll likely want to use &l:shiftwidth to only change the buffer local variable.
    – jamessan
    Mar 3, 2015 at 15:26
  • I'll mark this as accepted since it technically answers my question. I do still have to set both values separately if I wanna change tabstop/shiftwidth values in a running instance of vim. Mar 5, 2015 at 3:09

Might be a better way but you could always do this:

exec 'set shiftwidth=' . &tabstop


Specifically in this case:


When 'sts' is negative, the value of 'shiftwidth' is used.


When ['shiftwidth' is] zero the 'ts' value will be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.