Skip to content

Commit

Permalink
feat(nvim): leader-op to toggle markdown checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 30, 2023
1 parent 4c58ccb commit 21e535f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/neovim/config/after/ftplugin/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,22 @@ if require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then

-- TODO: add keymaps?
end

local bufnr = vim.api.nvim_buf_get_number(0)
vim.keymap.set("n", "<leader>op", function()
local cursor = vim.api.nvim_win_get_cursor(0)
local lineno = cursor[1]
local line = vim.api.nvim_buf_get_lines(bufnr, lineno - 1, lineno, false)[1] or ""
if string.find(line, "%[ %]") then
line = line:gsub("%[ %]", "%[x%]")
else
line = line:gsub("%[x%]", "%[ %]")
end
vim.api.nvim_buf_set_lines(bufnr, lineno - 1, lineno, false, { line })
vim.api.nvim_win_set_cursor(0, cursor)
end, {
noremap = true,
silent = true,
desc = "Toggle checkbox",
buffer = bufnr,
})

0 comments on commit 21e535f

Please sign in to comment.