1

I get a bit confused as to when we access a variable value like this:

:echom &textwidth
" 120

And when it's done like this:

:let a
" a                     #4

And when it's done like this:

:set textwidth?
textwidth=120

What is the difference between those three ways of getting the variable value, and when should they be properly used?

3

A variable named &name is the Vim script representation of the option name.

So &textwidth is the Vim script representation of the option textwidth.

See :h :let-&.

The let a just prints the value of the variable a. I would prefer :echo a here.

Addon: You also might want to read :help internal-variables to understand the name spaces of variables.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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