summaryrefslogtreecommitdiff
path: root/after/ftplugin/markdown.lua
blob: fe9be182b866b56fe0b0841c8f7e9989f3b2889c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
local function toggle_tick(buf, lnum, line, to)
    local beg, tick, rest = line:match("^(%s*)- %[([x ])%](.*)")
end

vim.keymap.set("n", "<CR>", 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 })