9

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?

Stephane Rolland
  • 1,857
  • 2
  • 13
  • 23
Chad Paradis
  • 517
  • 3
  • 7

3 Answers3

15

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.
akshay
  • 6,497
  • 37
  • 43
  • 2
    Note that you'll likely want to use &l:shiftwidth to only change the buffer local variable. – jamessan Mar 03 '15 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. – Chad Paradis Mar 05 '15 at 03:09
2

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

exec 'set shiftwidth=' . &tabstop

Steve Vermeulen
  • 1,067
  • 11
  • 13
0

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.

Koterpillar
  • 111
  • 3