Skip to content

Commit

Permalink
fix(nvim): improve leader-op
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Sep 6, 2023
1 parent f25e02f commit ab1fa36
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions modules/neovim/config/after/ftplugin/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ if require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then
require("user.zk")
vim.g.loaded_zk = 1
end

-- 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 ""
local line = vim.api.nvim_buf_get_lines(0, 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_buf_set_lines(0, lineno - 1, lineno, false, { line })
vim.api.nvim_win_set_cursor(0, cursor)
end, {
noremap = true,
silent = true,
desc = "Toggle checkbox",
buffer = bufnr,
buffer = 0,
})

0 comments on commit ab1fa36

Please sign in to comment.