From 4e4bd3beb90a4057ca97086bc4ba1acde109b65f Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 4 Nov 2022 16:35:44 +0100 Subject: vim: handle numbered lists with smart-o --- .vim/after/ftplugin/markdown.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to '.vim') diff --git a/.vim/after/ftplugin/markdown.lua b/.vim/after/ftplugin/markdown.lua index c827d17..226f9ed 100644 --- a/.vim/after/ftplugin/markdown.lua +++ b/.vim/after/ftplugin/markdown.lua @@ -44,9 +44,11 @@ vim.keymap.set('n', 'o', function() local node = vim.treesitter.get_node_at_pos(0, cursor[1]-1, cursor[2], {}) while node do if node:type() == 'list_item' then - vim.api.nvim_buf_set_lines(0, cursor[1], cursor[1], false, { - vim.treesitter.get_node_text(node:child(0), 0, {}) - }) + local ln = vim.treesitter.get_node_text(node:child(0), 0, {}) + local ln_start = string.match(ln, '^(%d+)%.'); if ln_start ~= nil then + ln = ln:gsub(ln_start, tonumber(ln_start)+1) + end + vim.api.nvim_buf_set_lines(0, cursor[1], cursor[1], false, {ln}) vim.api.nvim_feedkeys('jA', 'n', false) return end -- cgit 1.4.1