Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1022 - Using folds like grep

Created: October 20, 2005 16:13 Complexity: intermediate Author: i5513 Version: 5.7 Karma: 22/10 Imported from: Tip#1022

It doesn't work exactly like grep, but I hope it will useful for someone:


set foldmethod=expr
set foldexpr=getline(v:lnum)!~\"regex\"


Now you can do zM and edit your grep result

Remember zR to go back


Thanks for vim !

Comments

Sorry, this tip is for vim v6.0. Folds is a 6.0 feature I think

grimbys--AT--hotmail.com , October 20, 2005 16:20


This tip is kool. Replace regexp with your actual reg exp of course

set foldexpr=getline(v:lnum)!~\"function.*load\"

Now you can actually edit in this mode/view (this is how this method differs from a :g/regexp/)

zzapper , October 21, 2005 5:11


In addition, if you want to fold on your current search conditions, you can change the condition to be

set foldexpr=getline(v:lnum)!~--AT--/

Then, each time you search, you can simply refresh the folds with

set foldmethod=expr

(which forces the folds to update to the new search expression; and can be easily mapped).

vim.tip--AT--thechases.com , October 21, 2005 5:55


Advertisement