[PATCH] Printing column number for matched text

20 views
Skip to first unread message

Eric Van Dewoestine

unread,
Oct 23, 2008, 11:54:28 PM10/23/08
to ack-...@googlegroups.com
I recently started using ack inside of vim (set grepprg=ack) which is
a huge improvement in functionality over the standard :grep and a huge
speed boost over :vimgrep when working over a nfs mount.

However, I quickly became annoyed at the lack of column number
information, which prevents vim from jumping to the actual matched
text.

So, to remedy the situation, I patched Ack.pm to support a new
--column option and to print the column number along with the line
number like so:

$ ack -H --text --column line somefile.txt
somefile.txt
1:6:some line matched
2:12:some other line matched

The change is pretty simple, but I'm new to ack and I'm not sure of
the full implications of this change. Hopefully this, or a similar
patch can be included to improve support for vim (and probably other
text editors as well).

NOTE: the patch is against version 1.86
--
eric

Ack.pm.diff

Ovid

unread,
Oct 29, 2008, 5:53:32 AM10/29/08
to ack-...@googlegroups.com
On Fri, Oct 24, 2008 at 3:54 AM, Eric Van Dewoestine <erva...@gmail.com> wrote:
> I recently started using ack inside of vim (set grepprg=ack) which is
> a huge improvement in functionality over the standard :grep and a huge
> speed boost over :vimgrep when working over a nfs mount.
>
> However, I quickly became annoyed at the lack of column number
> information, which prevents vim from jumping to the actual matched
> text.

That sounds very useful. I've also integrated ack into vim:

http://use.perl.org/~Ovid/journal/36430

As a quick hack, I jump to the matched text with:

execute "/\\v" . pattern

If you use simple Perl regular expressions, this will allow vim to
usually jump directly to the first match it finds (see "help \v" in
vim).

Cheers,
Ovid

Eric Van Dewoestine

unread,
Oct 29, 2008, 10:39:44 AM10/29/08
to ack-...@googlegroups.com

I took a quick look at your integration and it looks like it doesn't
integrate with vim's quickfix. It seems to concentrate on finding one
file at a time.

While this may satisfy your workflow quite well, my primary usage
takes heavy advantage of vim's quickfix support where I want to be
able to navigate around all matches. The patch I submitted makes such
usage much more pleasant as it allows :cnext, :cprev, etc. to place
the cursor directly on the match.

Hopefully the powers that be will consider the patch for mainline
integration.

--
eric

Andy Lester

unread,
Oct 29, 2008, 10:41:50 AM10/29/08
to ack-...@googlegroups.com

On Oct 29, 2008, at 9:39 AM, Eric Van Dewoestine wrote:

> While this may satisfy your workflow quite well, my primary usage
> takes heavy advantage of vim's quickfix support where I want to be
> able to navigate around all matches. The patch I submitted makes such
> usage much more pleasant as it allows :cnext, :cprev, etc. to place
> the cursor directly on the match.


I don't understand. Are you talking about a patch to vim, or
something we should be doing in ack?

--
Andy Lester => an...@petdance.com => www.petdance.com => AIM:petdance

Eric Van Dewoestine

unread,
Oct 29, 2008, 10:54:12 AM10/29/08
to ack-...@googlegroups.com

My original mail[1] includes a patch[2] to ack to allow it to print
the column number along with the line number for each match found.
The main motivation being integration with vim, but I would assume
that other editors could take advantage of the additional information
as well.

[1] http://groups.google.com/group/ack-users/browse_thread/thread/562cb329d515d2
[2] http://ack-users.googlegroups.com/attach/d876aa71645f7fbf/Ack.pm.diff?view=1&part=2

--
eric

Reply all
Reply to author
Forward
0 new messages