How do I store the value of a Vim option into a Vim variable?

You can prefix the option name with the ‘&’ character and assign the option value to a Vim variable using the “let” command. For example, to store the value of the ‘textwidth’ option into the Vim variable “old_tw”, you can use the following command:

    :let old_tw = &tw

To explicitly save buffer local options, use the prefix “l:”

    :let old_tw = &l:tw

If you want to explicitly select the global option, use the “g:” prefix to the option name. To do the opposite, to set the ‘textwidth’ option with the value stored in the ‘old_tw’ variable, you can use the following command:

    :let &tw = old_tw

Comments (1)


Pepsh Pepshinsky

Let’s see you to :help viminfo-file-name (option -i) :set viminfofile=NONE


Speak Your Mind