What's the difference between let and set in the vim editor?
I've always wondered why both of them exist?
Also, I'd be interested to hear its historical background.
There are two ways to use the Vim setting options: 1. Enable the options for an individual file inside the Vim session using :set Open the desired file in Vim, type any option using the :set command in the Normal mode, and press Enter.
l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.
:set is for setting options, :let for assigning a value to a variable.
It happens that the value for an option is linked to the name of the option prepended by a & (the &option-name construct then behaves very similar to "ordinary" variables). So, the following are equivalent:
:set tw=40 :let &tw=40 But, for example, assigning 50 to the global variable foo (:let g:foo=50) cannot be achieved with a :set command (because g:foo is a variable and not an option).
Some options are boolean like. When setting these, no value is needed (as in :set noic and the opposite :set ic).
Set is a more user-friendly interface specialized for options
E.g.
:verbose set to display all options in effect.
:set tw=40 Will work as a shorthand for set textwidth=40
:set wrap& Will set the default value for option wrap
:set nowrap Will unset the option
:set wrap! Will toggle the option
Most importantly,
:setTab # to get tab completion!
Few of the above can (easily) be achieved with let.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With