Imngzx/jisho.nvim

website github github
language
stars 17
issues 0
subscribers 0
forks 0
CREATED

UPDATED


่พžๆ›ธ jisho.nvim ๐ŸŒธ


A blazing fast, zero-dependency Japanese dictionary plugin for Neovim, powered by Jisho.org.

Good for Japanese learners, anime enthusiasts, or anyone reading Japanese documentation and source code.

[!WARNING] This plugin requires latest 0.13 nightly

Preview Image

Layout Previews

โœจ Features

  • Blazing Fast & Async: Built on Neovim 0.13+ vim.async, native vim.system(), and vim.net.request() with automatic retries. Never blocks your UI.
  • Zero Dependencies: Works out of the box. No external plugins required. (optional: snacks.nvim, budoux.lua)
  • Beautiful Markdown: Parses dictionary data into clean, readable Markdown with other forms, tags, sense info, see-also, and sense tags.
  • Smart UI: Automatically integrates with snacks.nvim if installed. Falls back to a handcrafted, beautiful native Neovim floating window if not.
  • Persistent Cache: Disk cache at ~/.cache/nvim/jisho_cache.json survives Neovim restarts with 5-minute TTL.
  • Request Deduplication: In-flight tracking prevents duplicate API calls for the same word.
  • Search History: :JishoHistory command with timestamps, Enter to re-search (snacks.picker + native fallback).
  • Navigation: j/k jump between senses/entries, w/b Budoux-aware Japanese word jumps.
  • Modern Neovim APIs: Uses vim.iter, vim.uv, vim.bo/vim.wo, vim.net.request with retries.
  • Vibe Coded: Minimalist code, extreme performance, examined by author.

๐Ÿ“ฆ Installation

Method 1: Native vim.pack (No plugin manager needed)

You can install this plugin using Neovim's built-in package manager, or just clone it into your packpath:

vim.pack.add('https://github.com/Imngzx/jisho.nvim')

Then, add the setup and keymaps to your init.lua:

require('jisho').setup()

-- Setup keymaps
vim.keymap.set('n', '<leader>tj', function() require('jisho').search() end, { desc = 'Jisho (Word under cursor)' })
vim.keymap.set('v', '<leader>tj', function()
   vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
   vim.schedule(function()
   local s = vim.api.nvim_buf_get_mark(0, '<')
   local e = vim.api.nvim_buf_get_mark(0, '>')
   local lines = vim.fn.getregion({ 0, s[1], s[2] + 1, 0 }, { 0, e[1], e[2] + 1, 0 })
   require('jisho').search(table.concat(lines, ' '))
end, { desc = 'Jisho (Selection)' })

Method 2: lazy.nvim

{
  "Imngzx/jisho.nvim",
  cmd = { "Jisho", "JishoHistory", "JishoDedupe", "JishoRefresh" },
  keys = {
    {
      '<leader>tj',
      function() require('jisho').search() end,
      mode = 'n',
      desc = 'Jisho (Word under cursor)',
    },
    {
      '<leader>tj',
      function()
        vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
        vim.schedule(function()
          local s = vim.api.nvim_buf_get_mark(0, '<')
          local e = vim.api.nvim_buf_get_mark(0, '>')
          local lines = vim.fn.getregion({ 0, s[1], s[2] + 1, 0 }, { 0, e[1], e[2] + 1, 0 })
          require('jisho').search(table.concat(lines, ' '))
        end)
      end,
      mode = 'v',
      desc = 'Jisho (Selection)',
    },
  },
  opts = {},
}

Method 3: Resonance.nvim

require('resonance').load({
  'https://github.com/Imngzx/jisho.nvim',

  -- optional
  dependencies = { 'https://github.com/atusy/budoux.lua', },

  cmd = { 'Jisho' },

  keys = {
    { 'n', '<leader>tj', function() require('jisho').search() end, { desc = 'Jisho (Word under cursor)' } },
    { 'v', '<leader>tj', function()
      vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
      vim.schedule(function()
        local s = vim.api.nvim_buf_get_mark(0, '<')
        local e = vim.api.nvim_buf_get_mark(0, '>')
        local lines = vim.fn.getregion({ 0, s[1], s[2] + 1, 0 }, { 0, e[1], e[2] + 1, 0 })
        require('jisho').search(table.concat(lines, ' '))
      end)
    end, { desc = 'Jisho (Selection)' } },
  },

  config = function()
    require('jisho').setup({
      use_budoux = true,
      layout = 'spacious',
    })
  end,
})

โš™๏ธ Configuration

jisho.nvim works perfectly without any configuration, but you can customize the UI behavior.

require('jisho').setup({
  -- Auto-detect snacks.nvim by default.
  -- Set to false to force use native Neovim floating window.
  -- Set to true to force use snacks.nvim.
  use_snacks = pcall(require, 'snacks'),

  -- Auto-detect budoux.lua by default.
  -- can set to true or false
  use_budoux = pcall(require, 'budoux'),
  
  -- Settings for the native floating window (used when snacks is not available)
  window = {
    width = 0.6,      -- 60% of screen width
    height = 0.7,     -- 70% of screen height
    border = "rounded", -- "single", "double", "rounded", "solid", "shadow"
  },

  -- compact | spacious | super_spacious
  layout = "spacious"
})

[!TIP] You can add it into which-key

Here's my jisho + my budoux and which-key configuration file for Neovim

๐Ÿš€ Usage

Command Line

You can search any word anywhere via the command line:

:Jisho ้ฃŸในใ‚‹
:Jisho hello

Keymaps

If you configured the keymaps as shown above:

  • Normal Mode: Press <leader>tj to translate the word directly under your cursor.
  • Visual Mode: Select any text and press <leader>tj to translate the selection.

User Commands

Command Description
:Jisho [word] Search for a word (uses word under cursor if omitted)
:JishoHistory Open search history picker (snacks.picker or native)
:JishoDedupe inflight Inspect in-flight requests
:JishoDedupe clear-inflight Clear all in-flight requests
:JishoDedupe clear-cache Clear search cache
:JishoDedupe refresh [word] Force refresh (bypasses cache)
:JishoRefresh [word] Shortcut for force refresh

Result Window Navigation

Key Action
j / k Jump between senses/entries
w / b Budoux-aware Japanese word jumps
q / <Esc> Close window
<CR> (in history) Re-search selected entry

๐Ÿค Requirements

  • Neovim >= 0.13.0 (uses vim.async, vim.system, and vim.net.request)
  • curl available in your system's PATH (fallback HTTP transport)
  • Budoux plugin optional - for Japanese word segmentation
  • snacks.nvim recommended for best UI experience
  • Markdown rendering plugin recommended for best markdown rendering

License

This project is licensed under the MIT License.