Array (List) functions in vimscript
07 Feb 2023Vimscript Array
s are called List
s. They have a set of rules and functions that I'll document here for my own reference:
Basics
- They are defined with
let myArray=['one', 'two', 'three']
- They are zero-indexed:
echo myArray[0]
isone
- They can be accessed from the end
echo myArray[-1]
isthree
Functions
add(myArray, 'four')
adds a new elements.myArray+=['four']
also worksget(myArray, 0, 'default value')
reads a value, with a fallbacklen(myArray)
returns3
index(myArray, 'three')
returns2
(or-1
if not found)join(myArray, '/')
returnsone/two/three
split('one/two/three', '/')
creates['one', 'two', 'three']
Source
Want to add something ? Feel free to get in touch on Twitter : @pixelastic