Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support character-wise visual mode word lookup #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion plugin/online-thesaurus.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let s:path = shellescape(expand("<sfile>:p:h") . s:script_name)


function! s:Lookup(word)
let reg_save = @@
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution still caused issues for me. Instead of saving the register here, we can just use the blackhole register on line 50 by replacing it with 1,$d _ and 56 silent! normal! gg5"_dd

silent! let l:thesaurus_window = bufwinnr('^thesaurus$')

if l:thesaurus_window > -1
Expand All @@ -61,6 +62,21 @@ function! s:Lookup(word)
exec 'resize ' . (line('$') - 1)
setlocal nomodifiable filetype=thesaurus
nnoremap <silent> <buffer> q :q<CR>
let @@ = reg_save
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes unnecessary.

endfunction

function! s:LookupVisual(mode)
" Only support character-wise visual mode
if a:mode == 'v'
let reg_save = @@
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still affects register "* in my setup. I guess it's better to use a named register like @a


silent exec ":normal! gvy"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes silent exec ':normal! gv"ay'

call s:Lookup(@@)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call s:Lookup(@a)


let @@ = reg_save
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let @a = reg_save

else
echo "No support for line-wise nor block-wise visual modes"
endif
endfunction

if !exists('g:online_thesaurus_map_keys')
Expand All @@ -69,7 +85,7 @@ endif

if g:online_thesaurus_map_keys
nnoremap <unique> <LocalLeader>K :OnlineThesaurusCurrentWord<CR>
vnoremap <unique> <LocalLeader>K y:Thesaurus <C-r>"<CR>
vnoremap <unique> <LocalLeader>K :<C-U>call <SID>LookupVisual(visualmode())<CR>
endif

command! OnlineThesaurusCurrentWord :call <SID>Lookup(expand('<cword>'))
Expand Down