You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
" fold by begin and end regexp
:ZFFoldBlock /begin_regexp/end_regexp/
" same as :ZFFoldBlock /regexp//
:ZFFoldIfMatch regexp
" same as :ZFFoldBlock //regexp/
:ZFFoldIfNotMatch regexp
sample
you may :call ZF_FoldBlockHelp() to show sample at any time
/{/}/ : normal block mode
{
in fold 1
{
in fold 2
}
in fold 1
}
/rem// : fold if match
rem in fold
rem in fold
//rem/ : fold if not match
in fold
in fold
rem not in fold
rem not in fold
/tag/tag/ : single tag mode
tag
in fold 1
tag
not in fold
tag
in fold 2
tag
regexp
use vim's regexp by default, see :h magic
if you have othree/eregex.vim installed, then perl style regexp would be used instead
you may force disable it by let g:ZFVimFoldBlock_disableE2v = 1
advanced
typical advanced usage:
" fold comments accorrding to file type
function! ZF_Plugin_ZFVimFoldBlock_comment()
let expr='\(^\s*\/\/\)'
if &filetype=='vim'
let expr.='\|\(^\s*"\)'
endif
if &filetype=='c' || &filetype=='cpp'
let expr.='\|\(^\s*\(\(\/\*\)\|\(\*\)\)\)'
endif
if &filetype=='make'
let expr.='\|\(^\s*#\)'
endif
let disableE2vSaved = g:ZFVimFoldBlock_disableE2v
let g:ZFVimFoldBlock_disableE2v = 1
call ZF_FoldBlock("/" . expr . "//")
let g:ZFVimFoldBlock_disableE2v = disableE2vSaved
echo "comments folded"
endfunction
nnoremap ZC :call ZF_Plugin_ZFVimFoldBlock_comment()<cr>
calling ZFFoldBlock would append fold instead of replace, before using the function, you may want to remove all fold by zE or zD manually
when fold with /expr_l/expr_r/ format, there's a special pattern for expr_r to reference submatches in expr_l (similar to :h /\1), the pattern format is \lN, where N is 1~9
for example, /<([a-z]+)>/</\l1>/ would result:
xxx // not in fold
<aa> // in fold
xxx // in fold
</aa> // in fold
xxx // not in fold
ZFVimFoldBlock
vim script to fold code blocks using regexp
if you like my work, check here for a list of my vim plugins
preview
see all virtual functions
:ZFFoldBlock //virtual/
filter out all comments
:ZFFoldBlock /^[\t]*#//
fold by xml tags
:ZFFoldBlock /<([a-z0-9_:\.]+)/<\/\l1>|\/>/
(withothree/eregex.vim
)how to use
use Vundle or any other plugin manager is recommended
when
othree/eregex.vim
installed (recommended), perl style regexp would be used instead of vim stylefoldmethod
must be set tomanual
by default,
foldmethod
would be set tomanual
whenZFFoldBlock
called, you may disable it bylet g:ZFVimFoldBlock_resetFoldmethodWhenUse=0
foldminlines
recommended set to0
, which allow fold even for single lineby default,
foldminlines
would be set to0
whenZFFoldBlock
called, you may disable it bylet g:ZFVimFoldBlock_resetFoldminlinesWhenUse=0
recommended to have these key map:
or, use the functions directly:
sample
you may
:call ZF_FoldBlockHelp()
to show sample at any time/{/}/
: normal block mode/rem//
: fold if match//rem/
: fold if not match/tag/tag/
: single tag moderegexp
use vim's regexp by default, see
:h magic
if you have othree/eregex.vim installed, then perl style regexp would be used instead
you may force disable it by
let g:ZFVimFoldBlock_disableE2v = 1
advanced
typical advanced usage:
calling
ZFFoldBlock
would append fold instead of replace, before using the function, you may want to remove all fold byzE
orzD
manuallywhen fold with
/expr_l/expr_r/
format, there's a special pattern forexpr_r
to reference submatches inexpr_l
(similar to:h /\1
), the pattern format is\lN
, whereN
is1~9
for example,
/<([a-z]+)>/</\l1>/
would result:https://github.com/ZSaberLv0/ZFVimFoldBlock
The text was updated successfully, but these errors were encountered: