learnvimscriptthehardway icon indicating copy to clipboard operation
learnvimscriptthehardway copied to clipboard

Ch19 Poor example for why we should use `let` instead of `set`

Open sedm0784 opened this issue 13 years ago • 2 comments

Chapter 19:

Why would we want to do this when we could just use set? Run the following commands:

:let &textwidth = &textwidth + 10
:set textwidth?

This time Vim displays "textwidth=110". When you set an option using set you can only set it to a single literal value.

But in this case we can also do exactly the same thing with set:

:set textwidth=100
:set textwidth+=10
:set textwidth?

Vim displays "textwidth=110".

sedm0784 avatar Apr 16 '12 10:04 sedm0784

Yeah, it's tough to come up with simple examples that don't require a lot of outside knowledge. If you can think of a good standalone example here let me know.

sjl avatar Oct 12 '12 23:10 sjl

One possible example would be a command to increase textwidth by 15% or something similar.

:let &textwidth = &textwidth * 115 / 100

That couldn't really be accomplished using :set (well there's ^= but that doesn't seem to work with a float.) Just a suggestion... Thanks for the excellent guide!!!

filbranden avatar Dec 28 '15 21:12 filbranden