@@ -538,7 +538,7 @@ nnoremap U <C-r>
538538nnoremap J mzJ`z
539539
540540" split line and preserve cursor position
541- nnoremap S mzi<CR><Esc > `z
541+ nnoremap S mzi<CR><ESC > `z
542542
543543" select what was just pasted
544544nnoremap <leader> v V`]
@@ -597,6 +597,26 @@ noremap n nzzzv
597597noremap N Nzzzv
598598
599599
600+ function ! GetVisualSelection ()
601+ let [l: l1 , l: c1 ] = getpos (" '<" )[1 :2 ]
602+ let [l: l2 , l: c2 ] = getpos (" '>" )[1 :2 ]
603+ let l: selection = getline (l: l1 , l: l2 )
604+ let l: selection [-1 ] = l: selection [-1 ][: l: c2 - 1 ]
605+ let l: selection [0 ] = l: selection [0 ][l: c1 - 1 :]
606+ return join (l: selection , " \n " )
607+ endfunction
608+
609+ " search for visually selected areas
610+ xnoremap * <ESC> /<C-r> =substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g")<CR><CR>
611+ xnoremap # <ESC> ?<C-r> =substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g")<CR><CR>
612+
613+ " prepare search based on visually selected area
614+ xnoremap / <ESC> /<C-r> =substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g")<CR>
615+
616+ " prepare substitution based on visually selected area
617+ xnoremap & <ESC> :%s/<C-r> =substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g")<CR> /
618+
619+
600620" -- spell checking ------------------------------------------------------------
601621
602622set spelllang = en " English only
0 commit comments