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

Folding Python code

Since we're working with Python code throughout this book, let's play with some folds in our code. First, you'll need to change a setting called foldmethod to indent in your .vimrc file:

set foldmethod=indent
Don't forget to reload your ~/.vimrc file by either restarting Vim or executing :source $MYVIMRC.

This will tell Vim to fold based on indentation (there are multiple ways to work with folds; see the following section, Types of folds, for more information).

Open animal_farm.py and you will see portions of our file folded away:

Navigate your cursor to one of the folded lines. Hitting zo will open the current fold:

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