local copy_indent_macro = "0\"_D" -- clear current line .. "?." -- find first non-empty line above .. "noh" -- clear highlight .. "^\"yy0" -- copy indentation to y register .. "" -- return to original line .. "\"yp" -- paste y register .. "A" -- enter insert mode vim.keymap.set({ "n" }, "o", "o" .. copy_indent_macro, { buffer = 0 }) vim.keymap.set({ "n" }, "O", "O" .. copy_indent_macro, { buffer = 0 }) vim.keymap.set({ "i" }, "", "" .. copy_indent_macro, { buffer = 0 })