O'Reilly logo

Mastering Vim by Ruslan Osipov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lists

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required