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

Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.

Introduction to Recursion and Backtracking

Sorting Algorithms

Introduction to C Programming Language

And More...

Speak Your Mind