restrict search only in set of rows or columns?

1 view
Skip to first unread message

Reckoner

unread,
Jul 22, 2009, 9:56:24 AM7/22/09
to vim_use
Hi,

is it possible to restrict the search to a specific number of columns
and/or rows ?

In other words, you can do:

:1,10s/old_pattern/new_pattern/

in order to get a substitution applied to a specific set of rows.
However, I'm interested in searching, not substituting, and I would
like to do it over a restricted number of rows or columns.

The files I am working with are not otherwise delimited in a special
way either row-wise or column wise.

Thanks in advance.

Tim Chase

unread,
Jul 22, 2009, 10:08:56 AM7/22/09
to vim...@googlegroups.com
> is it possible to restrict the search to a specific number of columns
> and/or rows ?

You'll want to read up at

:help /\%l
:help /\%v
:help /\%c

(well, you can just start at the %l version and continue reading
since they're serial). So you can do something like

/foo\%>20l\%<30l\%>5c\<%45c

to search for "foo" within the window (5,20)-(45,30) in your file
(well, ignore any fenceposting errors I might have made there...)

The %v and %c variants are the same (to determine the column)
except the %v version takes tab-expansion into consideration,
while the %c version takes literal character-counts into
consideration (both have their uses).

-tim


Reply all
Reply to author
Forward
0 new messages