search limit for / ?

16 views
Skip to first unread message

sinbad

unread,
Jul 24, 2012, 12:32:58 AM7/24/12
to vim...@googlegroups.com
how to limit the search to the current line while using / or ?

tnx

Christian Brabandt

unread,
Jul 24, 2012, 4:51:14 AM7/24/12
to vim...@googlegroups.com
On Tue, July 24, 2012 06:32, sinbad wrote:
> how to limit the search to the current line while using / or ?

Use search()

regards,
Christian

sc

unread,
Jul 24, 2012, 5:48:57 AM7/24/12
to vim...@googlegroups.com
On Tue, Jul 24, 2012 at 10:51:14AM +0200, Christian Brabandt wrote:
> On Tue, July 24, 2012 06:32, sinbad wrote:
> > how to limit the search to the current line while using / or ?

> Use search()

or f or F

sc

geoffr...@thomsonreuters.com

unread,
Jul 24, 2012, 6:25:40 AM7/24/12
to vim...@googlegroups.com
On Tuesday, 24 July 2012 05:32:58 UTC+1, sinbad wrote:
> how to limit the search to the current line while using / or ?

If you know the line number you can include \%106l in the search
pattern to match line 106 only.

You can also use Ctrl-R to call function line(".") to get the
current row number into the search pattern when you are typing it.

Putting it together you can make a mapping to do it for you such as
this command:

:noremap <F12> /\%<C-R>=line(".")<CR>l

Then use F12 instead of the / key

If you want / to always do this you can just do

:noremap / /\%<C-R>=line(".")<CR>l

although that might break any other configurations that assume
/ behaves in the usual way.

You can try the :noremap commands from the command mode
and if you like the behaviour, put them in your vimrc
file for future use.

regards,
Geoff

Reply all
Reply to author
Forward
0 new messages