3

I wrote some vim plugin, that correctly works with vim8, but when I try run it with neovim I get error about invalid expression in string:

let var = str_first .. str_second

When I change .. to . all works fine, so I want to ask: string concatenation by .. is right? Why vim support both operators . and .., but neovim support only .?

2
  • :help expr-..
    – Matt
    Dec 25, 2020 at 13:34
  • 2
    BTW. Neovim also supports both operators (at least, current beta version).
    – Matt
    Dec 25, 2020 at 13:36

1 Answer 1

5

The .. string concatenation operator was added to Vim fairly recently, as of version 8.1.1114 from April 2019.

The documentation at :help expr-.. explains the rationale for adding it:

For String concatenation .. is preferred, since . is ambiguous, it is also used for Dict member access and floating point numbers.

This commit has been ported to NeoVim in May 2019 and it's present in NeoVim v0.4.4, the latest release of NeoVim as of this writing.

If you care about compatibility with older versions, you might want to stick with using . as a string concatenation operator. It's still around and it's not really going anywhere anytime soon.

4
  • 1
    Or printf, which I find easier
    – D. Ben Knoble
    Dec 25, 2020 at 22:19
  • 1
    I'm still always using .: it works with every version of Vim I may still have to use. Dec 26, 2020 at 11:32
  • And by ambiguous they mean... that a programmer can misunderstand what a piece of code does? Or that under some conditions a piece of code might do something different?
    – x-yuri
    Dec 11, 2021 at 12:43
  • 1
    @x-yuri The ambiguities are unlikely to arise in real life (a .. b raises an error when a is a Dict and floating point only affects number literals), but it's still important because now when Vim sees a.b it can only decide what it is by checking if a is a Dict. Vim9script is trying to make the language faster, which typically involves some kind of bytecode compilation, and in that case knowing which case is which at compile time is important.
    – filbranden
    Dec 11, 2021 at 16:42

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.