Way to search for highlighted text?

0 views
Skip to first unread message

Mark S.

unread,
Nov 21, 2008, 1:19:09 PM11/21/08
to vim...@googlegroups.com
Hello!

Is there a way to highlight some text, and then have vim search for that
text? I know about using * on a single word, but what if I want to
search for two words?

Thanks!
Mark

David Fishburn

unread,
Nov 21, 2008, 1:24:11 PM11/21/08
to vim...@googlegroups.com

Gene Kwiecinski

unread,
Nov 21, 2008, 2:24:13 PM11/21/08
to vim...@googlegroups.com

I just yank visually-selected text to the clipboard and replace it on
the ':s///' line.

Remember to escape magic chars. Eg, if you highlight and grab a path
like

fooey_files/image.gif

go back and escape the '/' with a '\', ie,

fooey_files\/image.gif

before continuing.

I don't know of any "direct" way of doing so, but you might be able to
set some mouse option to automagically yank to the clipboard any
visually-selected text. I normally eschew using the mouse, so I'm not
that familiar with mouse options.

Marc Weber

unread,
Nov 21, 2008, 2:24:58 PM11/21/08
to vim...@googlegroups.com

The easiest way is using word1\|word2 however both will be higlighited
in the same color then..

Marc Weber

Mark S.

unread,
Nov 21, 2008, 2:31:36 PM11/21/08
to vim...@googlegroups.com
Hi David,

Thank you!

-- Mark

--- On Fri, 11/21/08, David Fishburn <dfishb...@gmail.com> wrote:

> From: David Fishburn <dfishb...@gmail.com>
> Subject: Re: Way to search for highlighted text?
> To: vim...@googlegroups.com
> Date: Friday, November 21, 2008, 10:24 AM
> On Fri, Nov 21, 2008 at 1:19 PM, Mark S.
> <thro...@yahoo.com> wrote:
> > Is there a way to highlight some text, and then have
> vim search for that
> > text? I know about using * on a single word, but what
> if I want to
> > search for two words?
>

Mark S.

unread,
Nov 21, 2008, 2:58:44 PM11/21/08
to vim...@googlegroups.com
Hello Gene,

Maybe a more important question then would be "how do you paste into the command line" ? Ctrl-V doesn't do it.

Thanks!
Mark


--- On Fri, 11/21/08, Gene Kwiecinski <gkwie...@dclab.com> wrote:

> From: Gene Kwiecinski <gkwie...@dclab.com>
> Subject: RE: Way to search for highlighted text?
> To: vim...@googlegroups.com
> Date: Friday, November 21, 2008, 11:24 AM
> >Is there a way to highlight some text, and then have vim
> search for
> that
> >text? I know about using * on a single word, but what
> if I want to
> >search for two words?
>

Gene Kwiecinski

unread,
Nov 21, 2008, 3:08:06 PM11/21/08
to vim...@googlegroups.com
>Maybe a more important question then would be "how do you paste
>into the command line" ? Ctrl-V doesn't do it.

<shift-insert> does.


(And if anyone starts in with, "But e-z-edit on kde gnome ultra running
4.2 through remote-X uses control-alt-shift-meta insert instead...", I
don't wanna hear it. Find what works for you, and use it, a'ight?)

StarWing

unread,
Nov 21, 2008, 4:25:30 PM11/21/08
to vim_use
select the words use 'v', and "ay/<C-R>a<CR>
maybe you can write it in your vimrc:
vmap <leader>fd "ay/<C-R>a<CR>

and press \fd when you want to search selected text.

but it just can used in character-oriented. in line-orented or block-
orented mode, it has no effect.

btw, i can't visit:http://vim.wikia.com/wiki/
Search_for_visually_selected_text
i don't know why.

Mark S.

unread,
Nov 21, 2008, 5:01:36 PM11/21/08
to vim...@googlegroups.com
Hi StarWing,

Thanks for the tip -- especially about <c-r>.

That should be useful by itself. It does seem like there ought to be a standard way (not using windows key-sequences and system clipboard) for transfering information from the text body to the command line.

Thanks!
Mark

--- On Fri, 11/21/08, StarWing <weasl...@sina.com> wrote:

> From: StarWing <weasl...@sina.com>
> Subject: Re: Way to search for highlighted text?
> To: "vim_use" <vim...@googlegroups.com>
> Date: Friday, November 21, 2008, 1:25 PM
> select the words use 'v', and
> "ay/<C-R>a<CR>
> maybe you can write it in your vimrc:
> vmap <leader>fd "ay/<C-R>a<CR>
>
> and press \fd when you want to search selected text.
>
> but it just can used in character-oriented. in line-orented
> or block-
> orented mode, it has no effect.
>
> btw, i can't visit:http://vim.wikia.com/wiki/
> Search_for_visually_selected_text
> i don't know why.
>
> On 11?22?, ??4?08?, "Gene Kwiecinski"

Gary Johnson

unread,
Nov 21, 2008, 6:01:20 PM11/21/08
to vim...@googlegroups.com
On 2008-11-21, "Mark S." <thro...@yahoo.com> wrote:
> Hi StarWing,
>
> Thanks for the tip -- especially about <c-r>.
>
> That should be useful by itself. It does seem like there ought to
> be a standard way (not using windows key-sequences and system
> clipboard) for transfering information from the text body to the
> command line.

:help c_CTRL-R
:help c_CTRL-R_CTRL-F

Also, since the 0 (zero) register holds the last text yanked, you
can highlight some text in the body, type y to yank it, then as
you're typing on the command line, type Ctrl-R and 0 to put that
text there. (You can put from the " register instead of from the 0
register, but I find 0 easier to type and it doesn't get overwritten
by deletes.)

:help quote0
:help quotequote

Regards,
Gary

Marc Weber

unread,
Nov 21, 2008, 6:22:46 PM11/21/08
to vim...@googlegroups.com
On Fri, Nov 21, 2008 at 02:01:36PM -0800, Mark S. wrote:
>
> Hi StarWing,
>
> Thanks for the tip -- especially about <c-r>.
>
> That should be useful by itself. It does seem like there ought to be a standard way (not using windows key-sequences and system clipboard) for transfering information from the text body to the command line.
>
> Thanks!
> Mark
Hi Mark,

You can yank to any register. (:h registers) which is done automatically
when you yank or delete text. You can also "ay to put into register a.
You then use (in cmd line or insert mode (buffer)) ctrl-r <register>
(<register> beeing etiher * + or one of the others..)
As alternative you can press q: to get a cmd line buffer window.
There you can yank/ copy /paste as normal.

cu Marc

Tony Mechelynck

unread,
Nov 21, 2008, 9:02:52 PM11/21/08
to vim...@googlegroups.com

1. Select the text using characterwise or linewise VISUAL (v or V), not
SELECT (i.e. not shift-cursor).
2. Yank it to the unnamed register using y
3. Start your command-line
/
4. Insert the unnamed register
Ctrl-R " (control-R then double-quote with no intervening space) -- see
":help c_CTRL-R"
5. If there are "special" characters in the just-pasted text (backslash,
forward slash, period, circumflex, dollar, opening bracket, asterisk),
backslash-escape them by editing the command-line -- see ":help
pattern-overview".
6. You may or may not want to insert \< (start word) and/or \> (end
word) at the ends of your search pattern. If you do, do it now, by
command-line editing.
7. Check your search command-line, then hit Enter. Voilà!


Best regards,
Tony.
--
"There is nothing which cannot be answered by means of my doctrine,"
said a monk, coming into a teahouse where Nasrudin sat. "And yet just
a short time ago, I was challenged by a scholar with an unanswerable
question," said Nasrudin. "I could have answered it if I had been
there." "Very well. He asked, 'Why are you breaking into my house in
the middle of the night?'"

Reply all
Reply to author
Forward
0 new messages