aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/vsearch.vim
blob: e1472f51c86c15042188a7f28bb63fe1457ea14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
" vsearch.vim
" Visual mode search
" Copied from https://github.com/godlygeek/vim-files/blob/master/plugin/vsearch.vim
function! s:VSetSearch()
  let temp = @@
  norm! gvy
  let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
  " Use this line instead of the above to match matches spanning across lines
  "let @/ = '\V' . substitute(escape(@@, '\'), '\_s\+', '\\_s\\+', 'g')
  call histadd('/', substitute(@/, '[?/]', '\="\\%d".char2nr(submatch(0))', 'g'))
  let @@ = temp
endfunction

vnoremap * :<C-u>call <SID>VSetSearch()<CR>/<CR>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>?<CR>