Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: What's the difference between let and set?

Tags:

vim

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.

like image 752
Dave Halter Avatar asked Apr 03 '12 09:04

Dave Halter


People also ask

What is set in Vim?

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.

What is let G in Vimrc?

l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.


2 Answers

: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).

like image 126
René Nyffenegger Avatar answered Sep 28 '22 02:09

René Nyffenegger


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.

like image 30
sehe Avatar answered Sep 28 '22 02:09

sehe