robin/ivy

my custom neovim config

git clone https://git.robinwobin.dev/robin/ivy

robinkeymaps: sort into files in `config/plugin/keymaps/`4fb7125

main
1.3 KiB38 linesraw
1-- https://github.com/echasnovski/nvim/blob/0a87022921d2e2a95fb987c4f11fc4804b57d6f9/plugin/21_functions.lua#L23
2
3vim.keymap.set("n", "<Plug>(ivy-insert-section)", function()
4  local lnum = vim.fn.line(".")
5  local symbol = "="
6  local total_width = vim.o.textwidth > 0 and vim.o.textwidth or 79
7
8  local indent = vim.fn.indent(lnum)
9  if indent == -1 then
10    return
11  end
12  -- on empty lines: inherit indent of previous non-empty line
13  local lnum_ = lnum
14  while
15    indent == 0
16    and #vim.api.nvim_buf_get_lines(0, lnum_ - 1, lnum_, true)[1] == 0
17    and lnum_ > 0
18  do
19    lnum_ = lnum_ - 1
20    indent = vim.fn.indent(lnum_)
21  end
22  local indent_str = string.rep(" ", indent)
23
24  -- use 'commentstring' with '%s' replaced by section symbols and prepended
25  -- with indent_str
26  local comment_string = vim.bo.commentstring
27  local comment_str_len = #comment_string:format("")
28  local content = string.rep(symbol, total_width - indent - comment_str_len)
29  local section_template = indent_str .. comment_string:format(content)
30  vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, true, { section_template })
31
32  -- start replace mode at inner start
33  local inner_start = comment_string:find("%%s") + indent
34  vim.fn.cursor(lnum, inner_start)
35  vim.cmd.startreplace()
36end)
37
38vim.keymap.set("n", "<leader>is", "<Plug>(ivy-insert-section)")