Vim Tips Wiki
Advertisement
Tip 1022 Printable Monobook Previous Next

created October 20, 2005 · complexity intermediate · author i5513 · version 6.0


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.

Comments

Replace regexp with your actual regular expression 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/).


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

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

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).


Advertisement