Sunday, May 16, 2010

Re: Search using the Highlighted text as pattern

On 16/05/10 09:32, Panciz wrote:
> Hi,
>
> with the * and # command it is possible to search (foward and backward)
> for the word nearest the cursor, is there a way to use an entire block
> of highlighted text as pattern for the search.
> This is very usefull when you want to search and replace for a
> long stringi composed by multiple words.
>
> Davide
>

Well, you can't yank into the search register; but you can yank into
some other register (such as the default register) and then copy that
into the search register:

(select visual area)
y
:let @/ = @@

and then

n

to search. However if the yanked block exceeds a line, or oversteps a
linebreak, you will have a what to Vim is a null (one byte) where a
search would need \n (two bytes) to match the line break. Similarly, any
full stops, slashes, question marks, asterisks, brackets, backslashes,
etc., will not be properly backslash-escaped in your search pattern.


Best regards,
Tony.
--
You need only reflect that one of the best ways to get yourself a
reputation as a dangerous citizen these days is to go about repeating
the very phrases which our founding fathers used in the struggle for
independence.
-- Charles A. Beard

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: