Skip to Content
Mastering Vim
book

Mastering Vim

by Ruslan Osipov
November 2018
Beginner
330 pages
7h 21m
English
Packt Publishing
Content preview from Mastering Vim

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Vim

Mastering Vim

Damian Conway
Vim Masterclass

Vim Masterclass

Jason Cannon
Modern Vim

Modern Vim

Drew Neil

Publisher Resources

ISBN: 9781789341096Supplemental Content