A Neovim plugin that translates text using the DeepL API with multiple output modes (float, replace, append).
curl command{
"walkersumida/deepl.nvim",
version = "*",
opts = {},
}
use {
"walkersumida/deepl.nvim",
config = function()
require('deepl').setup()
end,
}
Plug "walkersumida/deepl.nvim"
Set your DeepL API key in the DEEPL_API_KEY environment variable.
export DEEPL_API_KEY="your-api-key-here"
You can make this persistent by adding it to your shell configuration file (.bashrc, .zshrc, etc.).
Add the following to your init.lua or init.vim:
require('deepl').setup()
Currently, there are no configuration options, but they may be added in the future.
:DeepL <language_code> [--mode=<mode>] commandThe plugin supports three output modes:
float (default): Display translation in a floating windowreplace: Replace selected text with translationappend: Append translation below selected text (with an empty line)" Display translation in floating window (default)
:DeepL EN
:DeepL EN --mode=float
" Replace selected text with translation
:DeepL JA --mode=replace
" Append translation below selected text
:DeepL DE --mode=append
Examples of language codes:
EN - EnglishJA - JapaneseDE - GermanFR - FrenchES - SpanishIT - ItalianNL - DutchPL - PolishPT - PortugueseRU - RussianZH - ChineseKO - KoreanFor a complete list of supported languages, see the DeepL API documentation.
Example keybindings for convenience:
-- Translate to English (floating window)
vim.keymap.set('v', '<leader>te', ':DeepL EN<CR>', { desc = 'Translate to English' })
-- Translate to Japanese (floating window)
vim.keymap.set('v', '<leader>tj', ':DeepL JA<CR>', { desc = 'Translate to Japanese' })
-- Replace with English translation
vim.keymap.set('v', '<leader>tre', ':DeepL EN --mode=replace<CR>', { desc = 'Replace with English translation' })
-- Replace with Japanese translation
vim.keymap.set('v', '<leader>trj', ':DeepL JA --mode=replace<CR>', { desc = 'Replace with Japanese translation' })
-- Append English translation below
vim.keymap.set('v', '<leader>tae', ':DeepL EN --mode=append<CR>', { desc = 'Append English translation below' })
-- Append Japanese translation below
vim.keymap.set('v', '<leader>taj', ':DeepL JA --mode=append<CR>', { desc = 'Append Japanese translation below' })
When the translation result floating window is displayed:
q or ESC to closeDEEPL_API_KEY environment variable is not set
→ Check that the DEEPL_API_KEY environment variable is set.
curl error: ...
→ Check that the curl command is installed.
The DeepL API response may be incorrect. Check that your API key is valid.
Give a ⭐️ if this project helped you! Thank you!