yaohunzhanyue / collcetion

6 stars 0 forks source link

ZSaberLv0/ZFVimFoldBlock: fold code block using regexp, multiline supported, best fold plugin for general usage #83

Open yaohunzhanyue opened 4 years ago

yaohunzhanyue commented 4 years ago

ZFVimFoldBlock

vim script to fold code blocks using regexp

if you like my work, check here for a list of my vim plugins

preview

how to use

  1. use Vundle or any other plugin manager is recommended

    Plugin 'ZSaberLv0/ZFVimFoldBlock'
    

    when othree/eregex.vim installed (recommended), perl style regexp would be used instead of vim style

    Plugin 'othree/eregex.vim'
    
  2. foldmethod must be set to manual

    set foldmethod = manual
    

    by default, foldmethod would be set to manual when ZFFoldBlock called, you may disable it by let g:ZFVimFoldBlock_resetFoldmethodWhenUse=0

  3. foldminlines recommended set to 0, which allow fold even for single line

    set foldminlines=0
    

    by default, foldminlines would be set to 0 when ZFFoldBlock called, you may disable it by let g:ZFVimFoldBlock_resetFoldminlinesWhenUse=0

  4. recommended to have these key map:

    nnoremap ZB q::call ZF_FoldBlockTemplate()<cr>
    nnoremap ZF :ZFFoldBlock //<left>
    
  5. or, use the functions directly:

    " 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

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