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

Dictionaries

Dictionaries are also supported in Vim:

let animal_names = {  \ 'cat': 'Miss Cattington',  \ 'dog': 'Mr Dogson',  \ 'parrot': 'Polly'  \ }

As you may have noticed, you need to explicitly outline the line breaks with a backslash \ if you're defining a dictionary on multiple lines.

Dictionary modification operations are similar to the ones familiar to you from Python. Elements can be accessed in two ways:

let cat_name = animal_names['cat']  " get an elementlet cat_name = animal_names.cat     " another way to access an element

Accessing an element via . only works if the key contains numbers, letters, and underscores.

You can set or override a dictionary entry as follows:

let animal_names['raven'] = 'Raven R. Raventon'

Entries are removed ...

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