Skip to content

Neovim plugin that translates text using the DeepL API with multiple output modes (float, replace, append)

License

Notifications You must be signed in to change notification settings

walkersumida/deepl.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ deepl.nvim

A Neovim plugin that translates text using the DeepL API with multiple output modes (float, replace, append).

Neovim Lua License

Float Mode
Replace Mode
Append Mode

โœจ Features

  • Translate text selected in visual mode using the DeepL API
  • Multiple output modes:
    • Float mode: Display translation results in a floating window
    • Replace mode: Replace selected text with translation
    • Append mode: Append translation below selected text
  • User-specified target language
  • Simple and lightweight implementation

๐Ÿ“‹ Requirements

  • Neovim 0.7.0 or higher
  • DeepL API key (free or paid plan)
  • curl command

๐Ÿ“ฆ Installation

lazy.nvim

{
  "walkersumida/deepl.nvim",
  version = "*",
  opts = {},
}

packer.nvim

use {
  "walkersumida/deepl.nvim",
  config = function()
    require('deepl').setup()
  end,
}

vim-plug

Plug "walkersumida/deepl.nvim"

โš™๏ธ Configuration

DeepL API Key

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.).

Plugin Initialization

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.

๐Ÿš€ Usage

Basic Usage

  1. Select text in visual mode
  2. Run the :DeepL <language_code> [--mode=<mode>] command

Output Modes

The plugin supports three output modes:

  • float (default): Display translation in a floating window
  • replace: Replace selected text with translation
  • append: Append translation below selected text (with an empty line)

Examples

" 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

Supported Languages

Examples of language codes:

  • EN - English
  • JA - Japanese
  • DE - German
  • FR - French
  • ES - Spanish
  • IT - Italian
  • NL - Dutch
  • PL - Polish
  • PT - Portuguese
  • RU - Russian
  • ZH - Chinese
  • KO - Korean

For a complete list of supported languages, see the DeepL API documentation.

โŒจ๏ธ Keybinding Examples

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' })

๐ŸŽฎ Floating Window Controls

When the translation result floating window is displayed:

  • Press q or ESC to close

๐Ÿ”ง Troubleshooting

API Key Error

DEEPL_API_KEY environment variable is not set

โ†’ Check that the DEEPL_API_KEY environment variable is set.

curl Error

curl error: ...

โ†’ Check that the curl command is installed.

JSON Parse Error

The DeepL API response may be incorrect. Check that your API key is valid.

๐Ÿ“š References

โญ Show your support

Give a โญ๏ธ if this project helped you! Thank you!

About

Neovim plugin that translates text using the DeepL API with multiple output modes (float, replace, append)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages