1. 程式人生 > >vim外掛--python_fold程式碼收起/展開

vim外掛--python_fold程式碼收起/展開

created by
script type
utility
description
This script uses the expr fold-method to create folds for python source code. 

Folds are created for: 
- Class definitions 
- def function definitions 
- Blocks between {{{, }}} markers (but not yet {{{n, etc.) 

The fold level for each fold is equal to the indentation divided by the value of the 'shiftwidth' option, so make sure that 'shiftwidth' is set to the right value for your code. 

Class and function folds show a count of the number of lines in the fold and the documentation string when closed (contributed by Max Ischenko). 

Caveats: 
- The docstring is not shown when it is enclosed in single quotes (like '''comment'''); use double quotes instead (like """comment""") 
- Newest version relies on a blank line following class or function definition if the next bit of code is not a new class or function definition.  If this doesn't suit your programming style, use the _nonblank version 2.2 (nb).  That version is buggier, however.  Do not install both files. 

Bugs: 
- It occasionally inserts a bogus fold at complicated structures like conditionals that are followed by a blank line.  A work-around is to remove the blank line or to replace it with a line containing a comment (a single '#' will do)

install details

Choose either python_fold.vim or python_fold_nonblank.vim (do not use both at the same time!). 
Either save it in a file and source that file whenever you want to use the folding, or save it in your ftplugin directory (for example, ~/.vim/ftplugin) and it should load every time you edit python code.
在vim編輯器裡面編寫如下程式碼:(test.c)

//function()  {{{

int function() {

......

......

}

//}}}

這個函式體內容會被摺疊起來 顯示為:

23-30 lines: function() +--------------------------------------------------------+

把游標停留在該顯示行上 在非編輯模式下敲擊:

zo 展開
zc 收起
zn 全部展開
zN 全部摺疊

下載地址:http://vim.sourceforge.net/scripts/script.php?script_id=515