5

In my ~/.vimrc if I write set tabstop = 2, it will be a syntax error:

set tabstop = 2 " E521: Number required after =: tabstop =
set tabstop=2   " no errors

But I can write let @/ = ""

let @/ = "" " no errors
let @/=""   " no errors

Why are they different?

Note: Reading the help menu for both :h let and :h set you can find examples using the proper syntax; however, I'm still curious why they are different.

  • Presumably as a hangover from the original vi, which has a set command, but not a let. – muru Mar 3 '17 at 4:37
  • Are you aware of any documentation or mailing list files where this is mentioned? – mbigras Mar 3 '17 at 4:47
  • what? That original vi doesn't have a let? You can find the documentation (and vi itself) at ex-vi.sourceforge.net/ex.html – muru Mar 3 '17 at 4:49
  • 1
    I meant: have you come across folks discussing the sytnax of let for vim? It seems strange that they would choose to have let foo = 42 be valid when set foo = 42 is invalid. Does my question make sense? – mbigras Mar 3 '17 at 4:51
  • 1
    I agree that adding spaces between operators is a better choice for readability. The intention of my question isn't to argue for or against putting spaces between operators. The intention is to find some historical evidence/discussion behind the decision. For example, this question asks about why the order of two similar methods arguments was switched. It turns out the reasons are similar to what you're saying; however, the answer gave a richer historical account which I find interesting. – mbigras Mar 3 '17 at 5:03
2
                                                :set-args E487 E521
:se[t] {option}={value}         or
:se[t] {option}:{value}
                        Set string or number option to {value}.
                        For numeric options the value can be given in decimal,
                        hex (preceded with 0x) or octal (preceded with '0').
                        The old value can be inserted by typing 'wildchar' (by
                        default this is a <Tab> or CTRL-E if 'compatible' is
                        set).  See cmdline-completion.
                        White space between {option} and '=' is allowed and
                        will be ignored.  White space between '=' and {value}
                        is not allowed.

See the last two sentences. let does not have this limitation.

When you set a string with set option = value, Vim does not use quotes, so how would it know if you mean

  • "value" or
  • " value"?
| 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.