From 0d4ede9c0acfed001dc3dcd96b175ea13f483b6d Mon Sep 17 00:00:00 2001 From: Shahaf Arad Date: Tue, 7 Jul 2015 07:49:51 +0300 Subject: [PATCH 1/2] Support character-wise visual mode word lookup Support visual mode word lookup without overriding the unnamed register. --- plugin/online-thesaurus.vim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugin/online-thesaurus.vim b/plugin/online-thesaurus.vim index b1e72df..486df54 100644 --- a/plugin/online-thesaurus.vim +++ b/plugin/online-thesaurus.vim @@ -63,13 +63,27 @@ function! s:Lookup(word) nnoremap q :q endfunction +function! s:LookupVisual(mode) + " Only support character-wise visual mode + if a:mode == 'v' + let reg_save = @@ + + silent exec ":normal! gvy" + call s:Lookup(@@) + + let @@ = reg_save + else + echo "No support for line-wise nor block-wise visual modes" + endif +endfunction + if !exists('g:online_thesaurus_map_keys') let g:online_thesaurus_map_keys = 1 endif if g:online_thesaurus_map_keys nnoremap K :OnlineThesaurusCurrentWord - vnoremap K y:Thesaurus " + vnoremap K :call LookupVisual(visualmode()) endif command! OnlineThesaurusCurrentWord :call Lookup(expand('')) From 1b8217622d80d8652efde532b8bb3959903eb6cc Mon Sep 17 00:00:00 2001 From: Shahaf Arad Date: Fri, 10 Jul 2015 13:19:50 +0300 Subject: [PATCH 2/2] Fix overriding the default register in Lookup --- plugin/online-thesaurus.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/online-thesaurus.vim b/plugin/online-thesaurus.vim index 486df54..479e07f 100644 --- a/plugin/online-thesaurus.vim +++ b/plugin/online-thesaurus.vim @@ -35,6 +35,7 @@ let s:path = shellescape(expand(":p:h") . s:script_name) function! s:Lookup(word) + let reg_save = @@ silent! let l:thesaurus_window = bufwinnr('^thesaurus$') if l:thesaurus_window > -1 @@ -61,6 +62,7 @@ function! s:Lookup(word) exec 'resize ' . (line('$') - 1) setlocal nomodifiable filetype=thesaurus nnoremap q :q + let @@ = reg_save endfunction function! s:LookupVisual(mode)