sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #76: Folding for Quickfix

 tip karma   Rating 1/3, Viewed by 3044 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   June 8, 2001 5:27      complexity:   intermediate
author:   Mark A. Hillebrand      as of Vim:   6.0

The Quickfix mode aims to "speed up the edit-compile-edit cycle" according to ':help quickfix'. After executing ':make' or ':grep' it is possible to skim through the list of errors/matches and the appropriate source code locations with, for instance, the ':cnext' command.
Another way to get a quick overview is to use VIMs folding mode, to fold away all the error-free/match-free regions.
The script at the end of this message can be used for this purpose. It is at the moment not elaborate enough to put it up as a 'script'; but it might give someone inspiration to do so.
Big restrictions / bugs are as follows:
1. Vim Perl interface is required, i.e. the output of ':version' must contain '+perl' (People with Vim scripting knowledge might fix this)
2. Works only for one file, i.e. the current buffer.
3. It's a quick hack.
Sample usage: (a) edit a file, (b) do ':grep regexp %' to get a quickfix error list and (c) ':source foldqf.vim' will fold as described
Increasing the value of $CONTEXT gives you more context around the error regions.

Here comes it, it should be 7 lines:
---foldqf.vim
cwindow
perl $CONTEXT = 0;
perl @A = map { m/\|(\d+)\|/; $1 +0 } $curbuf->Get(1..$curbuf->Count());
close
normal zD
perl sub fold { VIM::DoCommand( $_[0] . ',' . ($_[1]) . "fold" ) if( $_[0] < $_[1] ); }
perl $last = 0; for (@A) { fold( $last+1+$CONTEXT, $_-1-$CONTEXT ); $last = $_; }; VIM::DoCommand(($A[-1]+1+$CONTEXT ) . ',$fold' );

 rate this tip  Life Changing Helpful Unfulfilling 

<< Remap CAPSLOCK key in Windows 2000 Professional and NT4.0 | Displaying search results using folds >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo