Vim Tips Wiki
(Reviewed, merged with Tip 108, tip is deprecated with syntax files.)
(dodgy, not deprecated: vb.vim doesn't include fold info)
Line 1: Line 1:
{{merged|108}}
 
{{deprecated|All functionality now covered by syntax folding files. See [[Folding|Tip 108: Folding]] for more information. Tip Deprecated.}}
 
 
{{TipImported
 
{{TipImported
 
|id=519
 
|id=519
Line 13: Line 11:
 
|category2=LanguageSpecific
 
|category2=LanguageSpecific
 
}}
 
}}
  +
{{dodgy|This functionality ''ought to be'' covered by syntax folding files. See [[Folding|Tip 108: Folding]] for more information. However it appears the vb.vim syntax file lacks any folding information. It would best be handled with an extension to or an alternate syntax script, not this awkward method.}}
  +
 
If you are using Microsoft Visual Studio .NET for editing Visual Basic .NET files, the Window Form Designer Generated Code is folded by default. If you want to have the same nice feature when editing the same file in Vim, put this code in your vimrc file so you can switch between the folded and unfolded mode:
 
If you are using Microsoft Visual Studio .NET for editing Visual Basic .NET files, the Window Form Designer Generated Code is folded by default. If you want to have the same nice feature when editing the same file in Vim, put this code in your vimrc file so you can switch between the folded and unfolded mode:
 
<pre>
 
<pre>

Revision as of 05:17, 12 January 2011

Tip 519 Printable Monobook Previous Next

created 2003 · complexity basic · author Eric Boucher · version 6.0


If you are using Microsoft Visual Studio .NET for editing Visual Basic .NET files, the Window Form Designer Generated Code is folded by default. If you want to have the same nice feature when editing the same file in Vim, put this code in your vimrc file so you can switch between the folded and unfolded mode:

function! NetFold()
  set foldmethod=syntax
  syn region myFold start="#Region" end="#End Region" fold
  syn sync fromstart
  set foldcolumn=2
endfunction

function! NetUnFold()
  set foldmethod=manual
  set foldcolumn=0
  norm zE
endfunction

So when your are editing a *.vb file, you simply have to call the function like this:

:call NetFold()
or
:call NetUnFold()

Also, if you want that little function to be called automatically when you edit a *.vb file, put these two lines in your _vimrc file:

autocmd BufNewFile,BufRead *.vb setfiletype vb
autocmd BufNewFile,BufRead *.vb call NetFold()

Comments

:g/^#R/,/^#E/fo