robin/ivy

my custom neovim config

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

robinplugin: do not set guicursor if config is empty37c60ce

main
1.8 KiB73 linesraw
1if vim.g.loaded_guicursor then
2  return
3end
4
5vim.g.loaded_guicursor = true
6
7local mode_lookup = {
8  normal = "n-v",
9  insert = "i-c-ci-ve",
10  replace = "r-cr",
11  operator = "o",
12  showmatch = "sm",
13}
14
15local type_lookup = {
16  block = "block",
17  vertical = "ver",
18  horizontal = "hor",
19}
20
21local function validate(mode, opts)
22  vim.validate("mode", mode, function(v)
23    return vim.tbl_contains({ "normal", "insert", "replace", "operator", "showmatch" }, v)
24  end, "valid mode")
25  vim.validate("opts", opts, function(v)
26    vim.validate("type", v.type, function(t)
27      return vim.tbl_contains({ "block", "vertical", "horizontal" }, t)
28    end, "valid type")
29    if v.type ~= "block" then
30      vim.validate("size", v.size, function(s)
31        return type(s) == "number"
32      end, "valid size with type ~= block")
33    end
34
35    vim.validate("animate", v.animate, function(anim)
36      vim.validate("wait", anim.wait, "number")
37      vim.validate("on", anim.on, "number")
38      vim.validate("off", anim.off, "number")
39      return true
40    end, true, "valid animation")
41
42    return true
43  end, "valid opts")
44end
45
46vim.once(function()
47  if not vim.g.guicursor_config or vim.tbl_isempty(vim.g.guicursor_config) then
48    return
49  end
50
51  local guicursorset = vim
52    .iter(pairs(vim.g.guicursor_config))
53    :map(function(mode, opts)
54      validate(mode, opts)
55
56      local s = string.format(
57        "%s:%s",
58        mode_lookup[mode],
59        opts.type ~= "block" and string.format("%s%d", type_lookup[opts.type], opts.size) or type_lookup[opts.type]
60      )
61
62      if opts.animate then
63        local anim = opts.animate
64        local anim_str = string.format("blinkwait%d-blinkon%d-blinkoff%d", anim.wait, anim.on, anim.off)
65        s = s .. "-" .. anim_str
66      end
67
68      return s
69    end)
70    :totable()
71
72  vim.opt.guicursor = table.concat(guicursorset, ",") .. ",a:Cursor/lCursor"
73end)