X-Git-Url: https://git.madduck.net/etc/lazyvim.git/blobdiff_plain/a71412ea7e1310a3e035fbcd414d3540e92764a5..32b20abc5b942d22d7fdbcef8b8547ce5851f765:/.config/lazyvim/after/ftplugin/markdown.lua?ds=sidebyside diff --git a/.config/lazyvim/after/ftplugin/markdown.lua b/.config/lazyvim/after/ftplugin/markdown.lua index 304a852..dbd24dc 100644 --- a/.config/lazyvim/after/ftplugin/markdown.lua +++ b/.config/lazyvim/after/ftplugin/markdown.lua @@ -4,3 +4,38 @@ if not i then end vim.g.table_mode_corner = "|" + +-- {{{ support { and } motions across quoted text/blockquotes +-- written by @seandewar on 2025-05-20 in #neovim:matrix.org +local function make_jump_fn(backwards) + return function() + local skip_flags = "W" .. (backwards and "be" or "") + local jump_flags = "c" .. skip_flags + local at_end = false + + for _ = 1, vim.v.count1 do + local lnum = vim.api.nvim_win_get_cursor(0)[1] + -- First, check whether the cursor is already between paragraphs (in an + -- empty line/block), and skip past it if we are + if vim.fn.search([[^$]], "ncW", lnum) ~= 0 then + at_end = vim.fn.search([[.]], skip_flags) == 0 + elseif vim.fn.search([[^\%(>\s*\)\+\zs$]], "ncW", lnum) ~= 0 then + -- In-between paragraphs inside a (possibly nested) block. + local depth = select(2, vim.fn.getline(lnum):gsub(">", "")) + at_end = vim.fn.search(([[^\%%(\%%(>\s*\)\{%u}$\)\@!.*$]]):format(depth), skip_flags) == 0 + end + + -- Finally, jump past the next paragraph, or to the beginning/end of the + -- buffer if there's no more + if at_end or vim.fn.search([[^$\|^\%(>\s*\)\+\zs$]], jump_flags) == 0 then + vim.fn.cursor(backwards and 1 or "$", backwards and 1 or vim.v.maxcol) + return + end + end + end +end + +vim.keymap.set({ "n", "v" }, "}", make_jump_fn(false), { buffer = true }) +vim.keymap.set({ "n", "v" }, "{", make_jump_fn(true), { buffer = true }) + +-- }}}