官术网_书友最值得收藏!

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:

Whenever your cursor is over a potential fold (an indented chunk of code in this example), zc will close the fold.

To visualize where folds are, you can use :set foldcolumn=N, where N is 0..12. This will dedicate the first N columns to the left of the screen to indicate folds with the  - (beginning of an open fold), | (contents of an open fold), and  + (closed fold) symbols.

You can also use za to toggle folds (open closed folds and close open folds).

You can open and close all folds in the file at the same time using zR and zM, respectively.

Setting an automatic  foldmethod  setting (such as  indent ) will display all files as folded by default. It's a matter of preference, and you may prefer to have the folds open when opening a new file. Adding  autocmd BufRead * normal zR  to your  .vimrc  file will keep the folds open as you open new files. This command tells Vim to execute zR (open all folds) when reading a buffer.
主站蜘蛛池模板: 海口市| 武乡县| 赫章县| 莱芜市| 宽甸| 儋州市| 万载县| 买车| 清水县| 新田县| 二连浩特市| 南部县| 比如县| 临邑县| 永清县| 拜泉县| 宁强县| 咸宁市| 莫力| 江口县| 固原市| 瑞丽市| 龙岩市| 武夷山市| 德保县| 和田市| 永泰县| 衡水市| 天祝| 平远县| 萨嘎县| 揭阳市| 北海市| 灵石县| 福海县| 拜泉县| 海口市| 七台河市| 黔南| 卢湾区| 襄城县|