local function toggle_tick(buf, lnum, line, to) local beg, tick, rest = line:match("^(%s*)- %[([x ])%](.*)") end vim.keymap.set("n", "", function() local curline = vim.fn.getline(".") local lnum = vim.fn.getpos(".")[2] local beg, tick, rest = curline:match("^(%s*)- %[([x ])%](.*)") if beg == nil then return end local new_tick = (tick == " " and "x" or " ") local new_line = beg .. "- [" .. new_tick .. "]" .. rest vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, false, { new_line }) end, { buffer = true })