Vim Tips Wiki
(Fix broken braces terminating tip template + slight clean)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=741
 
|id=741
  +
|previous=740
|title=Outline editing of Python programmes
 
  +
|next=742
 
|created=June 7, 2004
 
|created=June 7, 2004
 
|complexity=intermediate
 
|complexity=intermediate
Line 8: Line 9:
 
|version=6.0
 
|version=6.0
 
|rating=21/11
 
|rating=21/11
|text=
 
 
}}
 
}}
 
 
With the folding function of Vim6 (+folding), we can edit the Python programs similar to outline program editors such as SciTE.
 
With the folding function of Vim6 (+folding), we can edit the Python programs similar to outline program editors such as SciTE.
   
Line 43: Line 42:
 
You can use the folding functions (zm, zM, zr, zR, xa, zo, zc, zx...) in editing Python programs.
 
You can use the folding functions (zm, zM, zr, zR, xa, zo, zc, zx...) in editing Python programs.
   
== Comments ==
+
==Comments==
 
Or you could use the python_fold script ({{Script|id=515}}).
 
Or you could use the python_fold script ({{Script|id=515}}).
   

Revision as of 01:27, 11 November 2007

Tip 741 Printable Monobook Previous Next

created June 7, 2004 · complexity intermediate · author Lee Chun Kin · version 6.0


With the folding function of Vim6 (+folding), we can edit the Python programs similar to outline program editors such as SciTE.

Add the following lines to vimrc:

augroup python_prog
au!
fun! Python_fold()
  execute 'syntax clear pythonStatement'
  execute 'syntax keyword pythonStatement break continue del'
  execute 'syntax keyword pythonStatement except exec finally'
  execute 'syntax keyword pythonStatement pass print raise'
  execute 'syntax keyword pythonStatement return try'
  execute 'syntax keyword pythonStatement global assert'
  execute 'syntax keyword pythonStatement lambda yield'
  execute 'syntax match pythonStatement /\<def\>/ nextgroup=pythonFunction skipwhite'
  execute 'syntax match pythonStatement /\<class\>/ nextgroup=pythonFunction skipwhite'
  execute 'syntax region pythonFold start="^\z(\s*\)\%(class\|def\)" end="^\%(\n*\z1\s\)\@!" transparent fold'
  execute 'syntax sync minlines=2000 maxlines=4000'
  set autoindent
  set foldmethod=syntax
  " set foldopen=all foldclose=all
  set foldtext=substitute(getline(v:foldstart),'\\t','\ \ \ \ ','g')
  set fillchars=vert:\|,fold:\
  set tabstop=4 shiftwidth=4 nowrap guioptions+=b
endfun
autocmd FileType python call Python_fold()
augroup END

You can use the folding functions (zm, zM, zr, zR, xa, zo, zc, zx...) in editing Python programs.

Comments

Or you could use the python_fold script (script#515).