Can I do this in Vimscript?
let [a, b] = s:MyFunc() function! s:MyFunc() return [1, 2] endfunction
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Yes you can, but Vim calls it list unpacking. It can be found in Vim's help:
Vim allows you to create and populate two variables from a list:
let [var1, var2] = mylist
which is equivalent to:
let var1 = mylist let var2 = mylist
There is also an (untagged) section on that help page titled "List unpack". It says you can do:
let [var1, var2; rest] = mylist
to collect an optional unknown number of items in a list.
And you can use a related trick to perform operations on multiple existing variables at once:
let [var1, var2] += 1
There is lots to like about this language.
However I don't believe any such magic is available for Dictionaries as of yet.