Skip to content

Instantly share code, notes, and snippets.

@quininer
Created November 3, 2015 03:22
Show Gist options
  • Save quininer/d69fb966b9757e1a48f6 to your computer and use it in GitHub Desktop.
Save quininer/d69fb966b9757e1a48f6 to your computer and use it in GitHub Desktop.
ydcv on vim
" 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