flashcards.nvim

Flashcards neovim plugin
git clone git://git.laack.co/flashcards.nvim.git
Log | Files | Refs

commit ad7a74b699e232dcd5c046fc6364ba7ac5339ef0
parent 6d426b20f0b0e7f8a6aa6d77035887ed7c6022e2
Author: Andrew Laack <andrew@laack.co>
Date:   Thu, 28 May 2026 13:07:19 -0500

Updated keybindings; fixed bug with closing buffer

Diffstat:
Mplugin/init.lua | 23+++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/plugin/init.lua b/plugin/init.lua @@ -101,16 +101,32 @@ local function flash() -- if this was already opened close and reopen because that's easier than figuring out if the window -- or buffer is rendered right now. - if state.win ~= nil then - vim.api.nvim_win_close(state.win, true) - end + + local begin_buf = state.buf ~= nil + if state.buf ~= nil then vim.api.nvim_buf_delete(state.buf, { force = true }) + state.buf = nil + end + + if begin_buf then + return end state.win = vim.api.nvim_get_current_win() state.buf = vim.api.nvim_create_buf(false, true) + + vim.api.nvim_buf_set_keymap(state.buf, "n", "<Left>", ":PreviousCard<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "<Right>", ":NextCard<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "<Up>", ":Flip<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "<Down>", ":Flip<CR>", {}) + + vim.api.nvim_buf_set_keymap(state.buf, "n", "h", ":PreviousCard<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "l", ":NextCard<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "k", ":Flip<CR>", {}) + vim.api.nvim_buf_set_keymap(state.buf, "n", "j", ":Flip<CR>", {}) + local row = 0 local col = 0 @@ -140,7 +156,6 @@ vim.api.nvim_create_user_command('Flip', flip_card, {}) vim.api.nvim_create_user_command('NextCard', next_card, {}) -- defaults first side vim.api.nvim_create_user_command('PreviousCard', previous_card, {}) -- defaults first side - -- TODO: Perhaps refactor 'Flash' -- TODO: Make commands more sensibly named -- how does vimwiki do it? Namespacing perhaps?