Skip to content

📕 Asynchronous translating plugin for Vim/Neovim

License

Notifications You must be signed in to change notification settings

keevan/vim-translator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-translator

CI

Asynchronous translating plugin for Vim/Neovim

Installation

Plug 'voldikss/vim-translator'

Features

  • Asynchronous translating
  • Floatwin(NeoVim) & popup(Vim8) support
  • Multi engines: bing, ciba, google, youdao, translate-shell
  • Save and export translation history
  • Proxy support(http, socks4, socks5)
  • No requirement for appid/appkey

Configuration

g:translator_target_lang

Target language

g:translator_source_lang

Source language

g:translator_default_engines

  • Available: 'bing', 'ciba', 'google', 'youdao', 'trans'

  • Default: ['ciba', 'youdao'] if g:translator_target_lang is 'zh', otherwise ['google', 'bing']

g:translator_proxy_url

e.g. let g:translator_proxy_url = 'socks5://127.0.0.1:1080'

  • Default: v:null

g:translator_history_enable

  • Default: v:false

g:translator_window_max_width

Max width value of the popup/floating window

  • Default: 0.6*&columns

g:translator_window_max_height

Max height value of popup/floating window

  • Default: 0.6*&lines

g:translator_window_borderchars

Floating window border will be disabled if g:translator_window_borderchars is v:null

  • Default: ['─', '│', '─', '│', '┌', '┐', '┘', '└']

g:translator_window_enable_icon

Set it to v:false if your terminal doesn't support Unicode symbols

  • Default: v:true

Key Mappings

This plugin doesn't supply any default mappings.

""" Configuration example
" Echo translation in the cmdline
nmap <silent> <Leader>t <Plug>Translate
vmap <silent> <Leader>t <Plug>TranslateV
" Display translation in a window
nmap <silent> <Leader>w <Plug>TranslateW
vmap <silent> <Leader>w <Plug>TranslateWV
" Replace the text with translation
nmap <silent> <Leader>r <Plug>TranslateR
vmap <silent> <Leader>r <Plug>TranslateRV

Once the translation window is opened, type <Leader>w again to jump into it and again to jump back

Commands

:Translate[!] [-e engines] [-t text] [-tl target_lang] [-sl source_lang]

Translate the text from the source language source_lang to the target language target_lang with engine, echo the result in the cmdline

If no engines, use g:translator_default_engines

If no text, use the text under the cursor

If no target_lang, use g:translator_target_lang

The command can also be passed to a range, i.e., :'<,'>Translate ..., which translates text in visual selection

If ! is included, the plugin will perform a reverse translating by switching target_lang and source_lang

:TranslateW[!] [-e engines] [-t text] [-tl target_lang] [-sl source_lang]

Like :Translate..., but display the translation in a window

:TranslateR[!] [-e engines] [-t text] [-tl target_lang] [-sl source_lang]

Like :Translate..., but replace the current text with the translation

:TranslateH

Export the translation history

Example:

:TranslateW -t text -e bing youdao -tl zh -sl en

Highlight

Here are the default highlight links. To customize, use hi or hi link

" Text highlight of translator window
hi def link TranslatorQuery             Identifier
hi def link TranslatorPhonetic          Type
hi def link TranslatorExplain           Statement
hi def link TranslatorDelimiter         Special

" Background of translator window border
hi def link TranslatorNF                NormalFloat
hi def link TranslatorBorderNF          NormalFloat

Known bugs

  • Can not translate sentences(because there are some spaces among words) in Vim8(see #24)

References

License

MIT

About

📕 Asynchronous translating plugin for Vim/Neovim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vim Script 66.2%
  • Python 33.8%