Array (List) functions in vimscript
07 Feb 2023Vimscript Arrays are called Lists. 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)returns3index(myArray, 'three')returns2(or-1if not found)join(myArray, '/')returnsone/two/threesplit('one/two/three', '/')creates['one', 'two', 'three']
Source
Want to add something ? Feel free to get in touch on Bluesky : @pixelastic.bsky.social