Created
November 3, 2015 03:22
-
-
Save quininer/d69fb966b9757e1a48f6 to your computer and use it in GitHub Desktop.
ydcv on vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" translate the word under cursor | |
function! SearchWord() | |
echo system('ydcv --', expand("<cword>")) | |
endfunction | |
" translate selected text | |
function! SearchWord_v(type, ...) | |
let sel_save = &selection | |
let &selection = "inclusive" | |
let reg_save = @@ | |
if a:0 | |
silent exe "normal! `<" . a:type . "`>y" | |
elseif a:type == 'line' | |
silent exe "normal! '[V']y" | |
elseif a:type == 'block' | |
silent exe "normal! `[\<C-V>`]y" | |
else | |
silent exe "normal! `[v`]y" | |
endif | |
echo system('ydcv --', @@) | |
let &selection = sel_save | |
let @@ = reg_save | |
endfunction | |
nnoremap <Leader>d :call SearchWord()<CR> | |
vnoremap <Leader>d :<C-U>call SearchWord_v(visualmode(), 1)<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment