]> git.madduck.net Git - etc/lazyvim.git/blobdiff - .config/lazyvim/after/ftplugin/markdown.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

{ and } motions in quoted text (markdown)
[etc/lazyvim.git] / .config / lazyvim / after / ftplugin / markdown.lua
index 304a8520b99beb06d05df3397279a4058660454d..dbd24dcd9173d0374077e9c385d6f6f5b4a0cca4 100644 (file)
@@ -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 })
+
+-- }}}