Neovim plugin to edit Anki card templates directly in the editor, with automatic synchronization via Anki-Connect.
This project adapts the VSCode extension anki-editor to Neovim, implemented in Lua instead of TypeScript.
- Neovim 0.6+ (0.10+ recommended for better
vim.system) - Anki desktop installed and running
- Anki-Connect add-on
- Anki Preview Reloader — refreshes previews in Anki when templates change
- nvim-notify — nicer notifications
- Telescope.nvim — improved selection UI (future)
- HTTP client for Anki-Connect with error handling
- Buffer management for Front, Back, and CSS
- Configuration system
:AnkiEditcommand for template selection and editing- Auto-sync on save (
:w) - Success/error notifications
- Connectivity check with
:AnkiPing
- Syntax highlighting for fields, filters, and conditionals
- Autocomplete for Anki fields and filters +- Diagnostics for template issues
- Rename for conditional tags ({{#if}} → {{/if}})
- LSP integration
- Rendered HTML preview
-- In your lazy.nvim spec:
{
'limaon/anki-editor.nvim',
event = 'VeryLazy',
config = function()
require('anki-editor').setup({
anki_connect_url = "http://127.0.0.1:8765",
})
end,
keys = {
{ '<leader>ne', ':AnkiEdit<CR>', desc = 'Edit Anki template' },
},
}Plug 'limaon/anki-editor.nvim'" In your init.vim or init.lua:
lua require('anki-editor').setup()- Clone the repository:
git clone https://github.com/limaon/anki-editor.nvim.git \
~/.local/share/nvim/site/pack/manual/start/anki-editor.nvim- Add setup to your
init.lua:
require('anki-editor').setup()require('anki-editor').setup({
-- Anki-Connect URL and port
anki_connect_url = "http://127.0.0.1:8765",
-- Optional API key (if configured in Anki-Connect)
api_key = nil,
-- Automatically sync on :w
auto_save = true,
-- Buffer name prefix
buffer_prefix = "[Anki]",
-- HTTP timeout (ms)
timeout_ms = 5000,
-- Debounce time for rapid saves (ms)
debounce_ms = 200,
-- Validate template before saving
check_on_write = true,
-- Notification provider: "vim.notify" or "nvim-notify"
notify_provider = "vim.notify",
})See examples/ for additional configurations (lazy.nvim, vim-plug).
:AnkiEdit " Interactive selection and editing of templates
:AnkiList " List available note types
:AnkiRefresh " Clear model cache
:AnkiPing " Check Anki-Connect connectivity- Run
:AnkiEdit - Select the note type (model)
- Select the card (e.g., "Card 1")
- Select the side (Front, Back, or Styling)
- The selected side opens in the current window (other sides are created in the background).
Use
:bnext,:bprevor:buffer [name]to switch to Back/Styling buffers. - Save with
:wto sync with Anki
-- In your init.lua
local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<leader>ne', ':AnkiEdit<CR>', opts)
vim.keymap.set('n', '<leader>nl', ':AnkiList<CR>', opts)
vim.keymap.set('n', '<leader>np', ':AnkiPing<CR>', opts)- Ensure Anki is running:
pgrep anki - Verify Anki-Connect is installed and enabled in Anki
- Test the URL:
curl http://127.0.0.1:8765 - Run
:AnkiPingin Neovim
:checkhealth
:messagesCheck if the plugin is in the runtimepath:
:set runtimepath?- Verify the Anki-Connect API is responding
- Check for errors in
:messages - Use
:AnkiListto validate connectivity
See development.md for:
- Local development setup
- Code style (StyLua, Luacheck)
- How to test locally
- How to contribute
- Fork the repository
- Your branch:
git checkout -b feature/your-feature - Clear commit messages
- Run
stylua lua/ plugin/for formatting - Run
luacheck lua/ --globals vimfor linting - Push:
git push origin feature/your-feature - Pull Request with description
- Inspired by anki-editor by Pedro Bronsveld for VSCode
- Anki-Connect by FooSoft
- Anki Documentation
- Neovim Lua API
- Anki-Connect API Reference
- Neovim plugin development guide
- PLANO.md — Roadmap and architecture