" VIM macros to make folding work more nicely, inspired by the Origami editor " Adam Sampson set fillchars="vert:|" "{{{ OrigamiFoldText set foldtext=OrigamiFoldText() function OrigamiFoldText() let line = getline(v:foldstart) let first = match(line, '\S') let space = strpart(line, 0, first) let pat = '(/\*\|\*/\|//\|--' for x in split(&foldmarker, ',') let pat = pat . '\|' . x endfor let pat = pat . ')\s*' let rest = substitute(strpart(line, first), pat, '', 'g') let lines = v:foldend - v:foldstart return space . '... ' . rest . ' (' . lines . ' lines)' endfunction "}}} "{{{ OrigamiCreateFold() " Second should insert fold markers and leave you typing the fold label. " Del/Backspace in Visual mode should take you back to Insert mode. function OrigamiCreateFold() endfunction "}}} "{{{ keybindings " Create/Remove Enter Exit " Delete.Char Open Close :map V :vmap :call OrigamiCreateFold() :vmap :vmap " Some terminals eat S-Ins themselves. :map :map x :map :map zo :map :map zc " These don't really do the right thing, because VIM automatically opens and " closes folds in Insert mode by default. :imap :imap a :imap a :imap a :imap a :imap a "}}}