> Added this to my .vimrc so I can use the selection (visual mode) as
> the search string.
>
> vmap / y/\V<c-r>"<cr>
>
> How can I make it search across multiple lines?
This idea has seen a lot of development in this list over the years.
The following is the version I'm using now, contributed to by
several people here along with additions of my own.
vnoremap <silent> * :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy/<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy?<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
vnoremap <silent> g* :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy/<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), '\_s\+', '\\_s\\+', 'g')<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
vnoremap <silent> # :<C-U>
\let old_reg=getreg('"')<bar>
\let old_regmode=getregtype('"')<cr>
\gvy?<C-R><C-R>=substitute(
\escape(@", '\\/.*$^~[]'), '\_s\+', '\\_s\\+', 'g')<cr><cr>
\:call setreg('"', old_reg, old_regmode)<cr>
I mapped these to the *-family of commands rather than to / because
/ can be useful in visual mode.
The * and # mappings allow multi-line search patterns. The g* and
g# mappings do also but ignore the type of whitespace so that they
will match the pattern phrase whether it is contained on one line or
wraps across lines.
HTH,
Gary
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment