November 2018
Beginner
330 pages
7h 21m
English
Vim also supports more complex data structures, such as lists and dictionaries. Here's an example of a list:
let animals = ['cat', 'dog', 'parrot']
Operations to modify lists are similar to the ones in Python. Let's take a look at some common operations.
You can get elements by index using the [n] syntax. Here are some examples:
let cat = animals[0] " get first elementlet dog = animals[1] " get second elementlet parrot = animals[-1] " get last element
Slices work in a similar way to Python, for instance:
let slice = animals[1:]
The value of slice would be ['dog, 'parrot']. The main difference from Python is that the end of the range is inclusive:
let slice = animals[0:1]
The value of slice would be ['cat', 'dog'].
To append to the list, ...