-- https://github.com/echasnovski/nvim/blob/0a87022921d2e2a95fb987c4f11fc4804b57d6f9/plugin/21_functions.lua#L23 vim.keymap.set("n", "(ivy-insert-section)", function() local symbol = "=" local total_width = vim.o.textwidth > 0 and vim.o.textwidth or 79 -- Insert template: 'commentstring' but with '%s' replaced by section symbols local comment_string = vim.bo.commentstring local comment_str_len = #comment_string:format("") local content = string.rep(symbol, total_width - comment_str_len) local section_template = comment_string:format(content) local okn = vim.fn.append(vim.fn.line("."), { section_template }) if okn == 1 then return end -- Enable Replace mode in appropriate place local inner_start = comment_string:find("%%s") vim.fn.cursor(vim.fn.line(".") + 1, inner_start) vim.cmd([[startreplace]]) end)