> -----Original Message----- > From: Lev Lvovsky [mailto:[EMAIL PROTECTED] > Sent: Tuesday, October 17, 2006 5:04 PM > To: vim@vim.org > Subject: search visual block > > Is it possible to search for a string by selecting that > string in visual mode? Meaning, if I highlight something, > and then want to search for that thing which is highlighted > in the rest of the doc? > > otherwise, is there a way to copy that string so that I can > later put it into the :/ command?
I know you have had lots of different reponses on this thread. This is what I keep in my vimrc, which doesn't use a function. Simply highlight the text and hit * or #, just like you would for a given work in normal mode. " Courtesy of Michael Naumann, Jürgen Krämer " Visually select text, then search for it if version >= 602 " Here are two enhanced versions of these mappings which use VIM 6.2's " getregtype() function to determine whether the unnamed register contains " a characterwise, linewise or blockwise selection. After the search has " been executed, the register *and* its type can then be restored with " setreg(). vnoremap <silent> * :<C-U> \let old_reg=getreg('"')<bar> \let old_regmode=getregtype('"')<cr> \gvy/<C-R><C-R>=substitute(substitute( \escape(@", '\\/.*$^~[]' ), "\n$", "", ""), \"\n", '\\_[[:return:]]', "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(substitute( \escape(@", '\\/.*$^~[]' ), "\n$", "", ""), \"\n", '\\_[[:return:]]', "g")<cr><cr> \:call setreg('"', old_reg, old_regmode)<cr> else " If you use both VIM 6.2 and older versions these mappings " should be defined depending on the current version. vnoremap <silent> * :<C-U>let old_reg=@"<cr> \gvy/<C-R><C-R>=substitute(substitute( \escape(@", '\\/.*$^~[]' ), "\n$", "", ""), \"\n", '\\_[[:return:]]', "g")<cr><cr> \:let @"=old_reg<cr> vnoremap <silent> # :<C-U>let old_reg=@"<cr> \gvy?<C-R><C-R>=substitute(substitute( \escape(@", '\\/.*$^~[]' ), "\n$", "", ""), \"\n", '\\_[[:return:]]', "g")<cr><cr> \:let @"=old_reg<cr> endif