goto insert mode from search

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

goto insert mode from search

Samuel Wright
Hi All

When searching for a string, how can I go into insert mode from a
specific string?

Should be obvious, right?

Thanks
Sam
Reply | Threaded
Open this post in threaded view
|

Re: goto insert mode from search

John (Eljay) Love-Jensen
Hi Samuel,

> When searching for a string, how can I go into insert mode from a
> specific string?

I don't think I understand quite what you are asking.

Because my non-flippant (but seemingly flippant) answer is, "Type
'/(searchstring)<CR>i'."  And you can press zero-or-more 'n' before the 'i'
to position to a specific instance of the specified search string.

--Eljay



Reply | Threaded
Open this post in threaded view
|

Re: goto insert mode from search

Tim Chase-2
>>When searching for a string, how can I go into insert mode from a
>>specific string?
>
> I don't think I understand quite what you are asking.
>
> Because my non-flippant (but seemingly flippant) answer is, "Type
> '/(searchstring)<CR>i'."  And you can press zero-or-more 'n' before the 'i'
> to position to a specific instance of the specified search string.

I have to side with Eljay here in my suspicion that it's easier
to just hit "i" after searching.  HOWEVER...if I understand what
you want, this hideous monstrosity may do the trick (beware...I
disclaim any damage this does to your brain, trying to unwind it)

nnoremap / :exec('cnoremap <'.'cr> <'.'cr>:exec("cunmap
<"."cr>")<'.'cr>i')<cr>/

(that should all be on one line, and typed literally).  It's a
mapping that creates a mapping on the fly that creates a mapping
on the fly...a meta-meta-mapping if you will.  Or maybe it's just
a meta-mapping?  I never meta-mapping I didn't like...until this
one :*)

Pressing "/" maps "<cr>" in command-mode to
    unmap "<cr>" and do go into insertion mode

It's got some ugly edge-cases too...if you use <esc> to cancel a
search, or ^J rather than ^M or "<cr>", it won't get to the
unmapping.  You might be able to work around it by playing with
the internal unmapping so that it maps to other things such as
<esc>, ^C, and ^J as well.  Blech.

But it does what I understand you wanted to do.

Talk about your morning calisthenics for the brain :-S

-tim




Reply | Threaded
Open this post in threaded view
|

Re: goto insert mode from search

Samuel Wright
Cheers for the feedback guys, will try to be clearer next time.

The '/(searchstring)<CR>i'."  And you can press zero-or-more 'n' before the 'i'
to position to a specific instance of the specified search string.

actually using ...<CR>4ni

to go to 4th instance.

was what I was looking for