From d8974bdb2e5e6dfaf53e74b62f3961726ee2d273 Mon Sep 17 00:00:00 2001 From: Thales Mello Date: Tue, 22 Aug 2017 01:03:40 -0300 Subject: [PATCH 1/4] Repeated star movement should move to the next word --- plugin/slash.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/slash.vim b/plugin/slash.vim index 6b99444..1924968 100644 --- a/plugin/slash.vim +++ b/plugin/slash.vim @@ -30,14 +30,19 @@ function! s:wrap(seq) endfunction function! s:immobile(seq) + if exists('b:repeated_move') + return a:seq + endif + let s:winline = winline() + let b:repeated_move = 1 return a:seq."\(slash-prev)" endfunction function! s:trailer() augroup slash autocmd! - autocmd CursorMoved,CursorMovedI * set nohlsearch | autocmd! slash + autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet b:repeated_move | autocmd! slash augroup END let seq = foldclosed('.') != -1 ? 'zo' : '' From 0bf02e2e937e358be7b4658bdaf359907d0cefb0 Mon Sep 17 00:00:00 2001 From: Thales Mello Date: Wed, 23 Aug 2017 01:06:00 -0300 Subject: [PATCH 2/4] Unlet repeated move variable silently --- plugin/slash.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/slash.vim b/plugin/slash.vim index 1924968..2697a7c 100644 --- a/plugin/slash.vim +++ b/plugin/slash.vim @@ -42,7 +42,7 @@ endfunction function! s:trailer() augroup slash autocmd! - autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet b:repeated_move | autocmd! slash + autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet! b:repeated_move | autocmd! slash augroup END let seq = foldclosed('.') != -1 ? 'zo' : '' From d8ad90ced0def7a7cecb2df1079410c3563642a3 Mon Sep 17 00:00:00 2001 From: Thales Mello Date: Wed, 23 Aug 2017 15:29:15 -0300 Subject: [PATCH 3/4] Rename repeated_move variable to include slash namespace --- plugin/slash.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/slash.vim b/plugin/slash.vim index 2697a7c..068c588 100644 --- a/plugin/slash.vim +++ b/plugin/slash.vim @@ -30,19 +30,19 @@ function! s:wrap(seq) endfunction function! s:immobile(seq) - if exists('b:repeated_move') + if exists('b:slash_repeated_move') return a:seq endif let s:winline = winline() - let b:repeated_move = 1 + let b:slash_repeated_move = 1 return a:seq."\(slash-prev)" endfunction function! s:trailer() augroup slash autocmd! - autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet! b:repeated_move | autocmd! slash + autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet! b:slash_repeated_move | autocmd! slash augroup END let seq = foldclosed('.') != -1 ? 'zo' : '' From b322817c528244fe27760cfc2fb1dc586053e345 Mon Sep 17 00:00:00 2001 From: Thales Mello Date: Wed, 23 Aug 2017 17:16:04 -0300 Subject: [PATCH 4/4] Implement visual star repeated movement --- plugin/slash.vim | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/plugin/slash.vim b/plugin/slash.vim index 068c588..efecf7b 100644 --- a/plugin/slash.vim +++ b/plugin/slash.vim @@ -29,20 +29,60 @@ function! s:wrap(seq) return a:seq."\(slash-trailer)" endfunction +function! s:set_repeated_move_type(seq) + " Vmaps work by replacing * and # with yank text then search the underlying + " word. We have to recognize these modes in order to override * and # keys + " in normal mode later, remapping then to n or N as desired. + + if mode() == 'v' && a:seq[0:1] ==# 'y/' + let b:slash_repeated_move = 'visual_forward' + elseif mode() == 'v' && a:seq[0:1] ==# 'y?' + let b:slash_repeated_move = 'visual_backward' + else + let b:slash_repeated_move = 'normal' + endif +endfunction + +function! s:revert_search_direction(key) + if a:key ==# 'n' + return 'N' + elseif a:key ==# 'N' + return 'n' + elseif + return a:key + endif +endfunction + +function! s:star_to_forward_backward(key) + if a:key ==# '*' + return 'n' + elseif a:key ==# '#' + return 'N' + else + return a:key + endif +endfunction + function! s:immobile(seq) - if exists('b:slash_repeated_move') + let repeated_move = get(b:, 'slash_repeated_move', '') + + if repeated_move ==# 'normal' return a:seq + elseif repeated_move ==# 'visual_forward' + return s:star_to_forward_backward(a:seq) + elseif repeated_move ==# 'visual_backward' + return s:revert_search_direction(s:star_to_forward_backward(a:seq)) endif let s:winline = winline() - let b:slash_repeated_move = 1 + call s:set_repeated_move_type(a:seq) return a:seq."\(slash-prev)" endfunction function! s:trailer() augroup slash autocmd! - autocmd CursorMoved,CursorMovedI * set nohlsearch | unlet! b:slash_repeated_move | autocmd! slash + autocmd CursorMoved,CursorMovedI * set nohlsearch | let b:slash_repeated_move = '' | autocmd! slash augroup END let seq = foldclosed('.') != -1 ? 'zo' : ''