Skip to content

Translate-shell.vim is a plugin for translating text without leaving Vim.

License

Notifications You must be signed in to change notification settings

echuraev/translate-shell.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

translate-shell.vim

Build Status Coverage Status License

Intro

Translate-shell.vim is a plugin for translating text without leaving Vim. It provides a window that displays the translate of word under cursor, selected text or you can use "on fly" translation and translate inserted text. Also, you can save your translate story to file and import it to Anki.

translate-shell.vim screencast

FZF functions:

translate-shell.vim fzf screencast

Table of Contents

Features

The following features are supported by translate-shell.vim:

  • Translate word under cursor.
  • Translate multi line string.
  • Select direction of translate from predefined list.
  • Interactive translation.
  • Open interactive terminal with translate-shell (only Vim 8).
  • Keep translate history. Choose the better translate to save.
  • Download audio for translation.
  • Import translation history to Anki.

Requirements

The following requirements have to be met in order to be able to use translate-shell.vim:

  • Install translate-shell. Translate-shell is used as a backend for the plugin. You can find it on github.

If you would like to use FZF functions that provided by this plugin, you have to install FZF. You can find installation instruction here.

Installation

You can install translate-shell.vim by using any vim plugin manager.

Installation with vim-plug

If you doesn't have installed translate-shell in path, you can install plugin by the following command:

Plug 'echuraev/translate-shell.vim', { 'do': 'wget -O ~/.vim/trans git.io/trans && chmod +x ~/.vim/trans' }

And after it you should specify path to translate-shell by defining g:trans_bin variable e.g:

let g:trans_bin = "~/.vim"

If you already have installed translate-shell in your PATH then it is enough to install plugin by the following command:

Plug 'echuraev/translate-shell.vim'

Getting Started

Translate-shell.vim provides the following commands for translation:

  • :Trans [{options}] - Translate word under cursor.
  • :'<,'>Trans [{options}] - Translate text in visual selection.
  • :TransSelectDirection - Translate word under cursor with selecting translate direction.
  • :'<,'>TransSelectDirection - Translate text in visual selection with selecting translate direction.
  • :TransInteractive [{options}] - Translate inserted text.
  • :TransTerm [{options}] - Open terminal with interactive translate-shell. That works only in Vim 8.
  • :TransOpenHistoryWindow - Open file with translate history.
  • :TransChangeDefaultDirection - Change default direction of translating for a session.

FZF functions:

  • :FZFTransSelectDirection - Translate word under cursor with selecting translate direction.
  • :'<,'>FZFTransSelectDirection - Translate text in visual selection with selecting translate direction.
  • :FZFTransInteractive - Translate inserted text.
  • :FZFTransChangeDefaultDirection - Change default direction of translating for a session.

For more convenience, you can create key mapping for these commands e.g:

inoremap <silent> <leader>t <ESC>:Trans<CR>
nnoremap <silent> <leader>t :Trans<CR>
vnoremap <silent> <leader>t :Trans<CR>
nnoremap <silent> <leader>td :TransSelectDirection<CR>
vnoremap <silent> <leader>td :TransSelectDirection<CR>

Codes of languages you can find here or run the following command:

trans -R

For more information please look at doc/trans.txt or open Vim and run :h trans.

Import history of translating to Anki

You can add history of your translation to Anki and learn new words. Full information you can find on wiki.

TODO List

  • Keep translate story
    • Choose the better translate to save
  • Nice syntax highlighting
  • Folding for translation on multiple languages
  • Possibility to join lines for better translation
  • Refactor and join translate functions (visual and not)
  • Async downloading audio for vim 8 (may be for all system calls)
  • Limit on the size of history files

References

Author

Egor Churaev [email protected]