On Thu, 4 May 2006 at 8:54pm, Yakov Lerner wrote: > On 5/4/06, Jack Donohue <[EMAIL PROTECTED]> wrote: > > > :v (and :g) made my day..! > > > > Yes, I use this a lot if I just want to filter out a set of lines, or see > > only lines containing some text (like the old XEDIT command). But what I'd > > really like to to is continue editing in this view and not lose all the > > hidden lines, more like folding. I expect folding can do this, but I've > > never gotten it to work and it seems pretty cumbersome. I'm looking for a > > simple solution involving maybe a couple of command I can make a map for. > > > > I guess I'm looking for a g or v command that folds the lines instead of > > actually deleting them. > > I guess the mappings below are simple enough. If you prefer > to keep it to just couple of lines, you can remove mapping for <F5> > and whole function TogglePatternBasedFolding(). What remains is > just 3 lines (maps for f2, f3, and f3). But I find tri-state toggle > (f5) also useful. > > " Simple pattern-based folding. > " How to use: (1) perform searh (so that vim remebers search pattern), > " (2) press f2, f3 f4, or press f5 repeatedly. > " > " F2 - fold lines that match current-search-pattern (cf :v//p) > " F3 - fold lines that do not match current-search-pattern (cf :g//p) > " F4 - open all folds > " F5 - tri-state toggle between f2-f3-f4 > > map <silent><F2> :set foldexpr=getline(v:lnum)=~@/ foldmethod=expr > foldenable<cr>zM > map <silent><F3> :set foldexpr=!(getline(v:lnum)=~@/) foldmethod=expr > foldenable<cr>zM > map <silent><f4> :set nofoldenable<cr> > map <silent><f5> :call TogglePatternBasedFolding()<cr> > > function! TogglePatternBasedFolding() > if &foldenable && &foldmethod=='expr' && &foldexpr[0] == '!' > :set nofoldenable | redraw | echo "all folds opened" > elseif &foldenable && &foldmethod=='expr' && &foldexpr[0] == 'g' > :set foldexpr=!(getline(v:lnum)=~@/) foldmethod=expr foldenable > normal zM > redraw | echo "lines not matching /".@/."/ folded" > else " &foldenable && &foldmethod=='expr' && &foldexpr[0] == 'g' > :set foldexpr=getline(v:lnum)=~@/ foldmethod=expr foldenable > normal zM > redraw | echo "lines matching /".@/."/ folded" > endif > endfun > > > Yakov
May I suggest that you take a look at my foldutil.vim? It allows folding by matching lines as well as other criterion, and also gives you the flexibility of specifying a context. http://www.vim.org/scripts/script.php?script_id=158 -- Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
