robin/ivy

my custom neovim config

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

robinoptions: enable 'previewpopup'fea68a8

main
9.6 KiB416 linesraw
1vim.on("User", nil, { pattern = "PackDone" }, function()
2  local colorscheme = vim.env.COLORSCHEME or "evergarden"
3  vim.cmd.colorscheme(colorscheme)
4end)
5vim.on("ColorScheme", nil, function(ev)
6  vim.env.COLORSCHEME = ev.match
7end)
8
9-- basics ======================================================================
10
11vim.o.encoding = "utf-8"
12
13-- basics · behavior ===========================================================
14
15vim.o.shell = os.getenv("SHELL") or "/bin/sh"
16
17-- enable .nvim.lua
18vim.o.exrc = true
19
20-- simplify jumps
21vim.o.jumpoptions = "stack,view,clean"
22
23-- open helpfiles on the right
24vim.o.keywordprg = ":vertical botright help"
25
26vim.o.formatoptions = "tcrqj"
27
28-- decrease update time
29vim.o.updatetime = 250
30
31-- basics · tui ================================================================
32
33vim.o.title = true
34vim.o.titlestring = '%{expand("%:p:~:.")} · nvim'
35vim.o.errorbells = false
36
37vim.o.mouse = "nv"
38
39vim.o.rulerformat = "%Ll %l:%c %3p%%"
40vim.o.colorcolumn = "+1"
41
42-- basics · keymaps ============================================================
43
44-- set ; as leader & ; + m as localleader
45vim.g.mapleader = ";"
46vim.g.maplocalleader = ";m"
47
48vim.o.timeout = false
49-- decrease mapped sequence wait time - displays which-key popup sooner
50vim.o.timeoutlen = 0
51
52-- basics · externals ==========================================================
53
54-- use rg for grepping
55vim.o.grepprg = vim.fn.executable("rg") == 1 and "rg --vimgrep -. --"
56  or "grep -rniI --"
57vim.o.grepformat = "%f:%l:%c:%m"
58vim.g.findprg = vim.fn.executable("fd") == 1
59    and "fd -H -p -t f --color=never --"
60  or "find . -type f -iregex '.*$*.*'"
61
62-- editor · appearance =========================================================
63
64-- always show statusline at the bottom
65vim.o.laststatus = 3
66vim.o.cmdheight = 0
67
68-- don't show the mode, since it's already in the status line
69vim.o.showmode = false
70vim.o.showcmd = false
71
72-- always show tabline
73vim.o.showtabline = 2
74
75-- always show 1 column of sign column (gitsigns, etc.)
76vim.o.signcolumn = "yes:1"
77
78-- hide search notices, intro
79vim.opt.shortmess:append("sI")
80
81-- line numbers
82vim.o.number = true
83vim.o.relativenumber = false
84vim.o.numberwidth = 3
85
86vim.o.cursorline = true
87vim.o.cursorlineopt = "both"
88
89-- use Cursor hl for editor cursor
90vim.opt.guicursor:append("a:Cursor/lCursor")
91
92-- hide extra text
93vim.o.conceallevel = 2
94vim.o.concealcursor = "c"
95
96vim.o.previewpopup = "height:12"
97
98-- editor · behavior ===========================================================
99
100-- split directions
101vim.o.splitbelow = true
102vim.o.splitright = true
103vim.o.splitkeep = "screen"
104
105-- allow cursor to move paste the end of the line in visual block mode
106vim.o.virtualedit = "block"
107
108-- scroll offsets
109vim.o.scrolloff = 5
110vim.o.sidescrolloff = 15
111-- smooth mousescroll
112vim.o.mousescroll = "ver:1,hor:1"
113
114-- substitution with preview window
115vim.o.inccommand = "split"
116
117-- editor · search =============================================================
118
119vim.o.hlsearch = true
120-- show search results while typing
121vim.o.incsearch = true
122-- ignore case when searching; use `\C` to reset
123vim.o.ignorecase = true
124-- infer letter cases for a richer built-in keyword completion
125vim.o.infercase = true
126-- don't ignore case when searching if pattern has upper case
127vim.o.smartcase = true
128
129-- editor · indents ============================================================
130
131-- indentations settings
132vim.o.shiftwidth = 2
133vim.o.tabstop = 2
134vim.o.expandtab = true
135vim.o.smarttab = true
136
137-- enable break indent
138vim.o.breakindent = true
139vim.o.wrap = true
140
141-- dont insert spaces on <tab>
142vim.o.softtabstop = 0
143
144vim.o.smartindent = true
145
146-- editor · session state ======================================================
147
148-- disable swap & backup, and configure undo files
149vim.o.swapfile = false
150vim.o.backup = false
151vim.o.writebackup = false
152vim.o.undodir = vim.fn.stdpath("state") .. "/undodir"
153vim.o.undofile = true
154-- dont unload abandoned buffers
155vim.o.hidden = true
156vim.o.sessionoptions = "help,tabpages,winsize"
157
158-- editor · completion =========================================================
159
160vim.o.pumheight = 8
161vim.o.pummaxwidth = 42
162
163vim.o.wildoptions = "pum"
164vim.o.wildmode = "noselect:full"
165
166vim.o.complete = ""
167vim.opt.completeopt = { "menuone", "preinsert", "noselect", "popup" }
168vim.opt.completeitemalign = { "kind", "abbr", "menu" }
169
170vim.o.autocomplete = true
171
172-- don't show autocomplete messages
173vim.opt.shortmess:append("c")
174
175-- editor · diagnostics ========================================================
176
177local signs = {
178  [vim.diagnostic.severity.ERROR] = "E",
179  [vim.diagnostic.severity.WARN] = "W",
180  [vim.diagnostic.severity.INFO] = "I",
181  [vim.diagnostic.severity.HINT] = "H",
182}
183local hl_map = {
184  [vim.diagnostic.severity.ERROR] = "DiagnosticError",
185  [vim.diagnostic.severity.WARN] = "DiagnosticWarn",
186  [vim.diagnostic.severity.INFO] = "DiagnosticInfo",
187  [vim.diagnostic.severity.HINT] = "DiagnosticHint",
188}
189
190vim.diagnostic.config({
191  float = {
192    header = "",
193    prefix = function(_, i)
194      return string.format("%d. ", i), "LineNr"
195    end,
196  },
197  jump = {
198    wrap = false,
199  },
200  signs = true,
201  status = {
202    format = function(d)
203      local items = {}
204      for level in ipairs(vim.diagnostic.severity) do
205        local count = d[level]
206        if count then
207          table.insert(
208            items,
209            ("%%#%s#%s %s"):format(hl_map[level], signs[level], count)
210          )
211        end
212      end
213
214      return table.concat(items, " ")
215    end,
216  },
217  virtual_text = {
218    hl_mode = "combine",
219  },
220})
221
222-- editor · listchars ==========================================================
223
224vim.o.list = true
225vim.opt.listchars:append({
226  eol = " ",
227  tab = "│ ",
228  trail = "-",
229  extends = "…",
230  precedes = "…",
231  nbsp = "␣",
232})
233
234-- editor · fillchars ==========================================================
235
236vim.opt.fillchars:append({
237  fold = " ",
238  eob = "·",
239  diff = "─",
240  foldopen = "▼",
241  foldclose = "▶",
242})
243
244-- editor · folds ==============================================================
245
246local function setfolds()
247  if vim.bo.buftype ~= "" then
248    vim.o.foldenable = false
249    return
250  end
251  vim.o.foldenable = true
252  vim.o.foldlevel = 99
253  vim.o.foldlevelstart = 99
254  vim.o.foldcolumn = "0"
255  vim.o.foldnestmax = 1
256  vim.o.foldmethod = "indent"
257end
258
259local foldgroup = vim.augroup("@ivy.folds.init", true)
260foldgroup({ "BufWinEnter", "VimEnter" }, function(ev)
261  vim.api.nvim_buf_call(ev.buf or 0, setfolds)
262end)
263foldgroup("OptionSet", { pattern = "buftype" }, function(ev)
264  vim.api.nvim_buf_call(ev.buf, setfolds)
265end)
266
267-- editor · spell check ========================================================
268
269-- let me have spelling checking for english
270vim.o.spelllang = "en_ca,en_gb,en_us"
271vim.opt.spelloptions:append("noplainbuffer")
272vim.o.spellsuggest = "double,4"
273-- use `data/site/spell/{lang}.add`
274vim.o.spellfile = ""
275vim.o.dictionary = "spell"
276
277-- editor · borders ============================================================
278
279---@type { [string]: { style: string, ['vert'|'vertleft'|'vertright'|'horiz'|'horizup'|'horizdown'|'verthoriz'|'topleft'|'topright'|'botleft'|'botright']: string, bottom?: string } }
280local borderchars = {
281  solid = {
282    style = "solid",
283    vert = "█",
284    vertleft = "█",
285    vertright = "█",
286    horiz = "▄",
287    horizup = "▀",
288    horizdown = "▄",
289    verthoriz = "█",
290    topleft = "▄",
291    topright = "▄",
292    botleft = "▀",
293    botright = "▀",
294    bottom = "▀",
295  },
296  single = {
297    style = "single",
298    vert = "│",
299    vertleft = "┤",
300    vertright = "├",
301    horiz = "─",
302    horizup = "┴",
303    horizdown = "┬",
304    verthoriz = "┼",
305    topleft = "┌",
306    topright = "┐",
307    botleft = "└",
308    botright = "┘",
309  },
310  double = {
311    style = "double",
312    vert = "║",
313    vertleft = "╣",
314    vertright = "╠",
315    horiz = "═",
316    horizup = "╩",
317    horizdown = "╦",
318    verthoriz = "╬",
319    topleft = "╔",
320    topright = "╗",
321    botleft = "╚",
322    botright = "╝",
323  },
324  rounded = {
325    style = "rounded",
326    vert = "│",
327    vertleft = "┤",
328    vertright = "├",
329    horiz = "─",
330    horizup = "┴",
331    horizdown = "┬",
332    verthoriz = "┼",
333    topleft = "╭",
334    topright = "╮",
335    botleft = "╰",
336    botright = "╯",
337  },
338  none = {
339    vert = "",
340    vertleft = "",
341    vertright = "",
342    horiz = "",
343    horizup = "",
344    horizdown = "",
345    verthoriz = "",
346    topleft = "",
347    topright = "",
348    botleft = "",
349    botright = "",
350  },
351  bold = {
352    vert = "┃",
353    vertleft = "┫",
354    vertright = "┣",
355    horiz = "━",
356    horizup = "┻",
357    horizdown = "┳",
358    topleft = "┏",
359    topright = "┓",
360    botright = "┛",
361    botleft = "┗",
362  },
363}
364
365vim.g.border_style = "single"
366-- my custom borderchars
367vim.g.bc = borderchars[vim.g.border_style]
368vim.g.bc_all = {
369  vim.g.bc.topleft,
370  vim.g.bc.top or vim.g.bc.horiz,
371  vim.g.bc.topright,
372  vim.g.bc.vert,
373  vim.g.bc.botright,
374  vim.g.bc.bottom or vim.g.bc.horiz,
375  vim.g.bc.botleft,
376  vim.g.bc.vert,
377}
378vim.opt.fillchars:append({
379  horiz = vim.g.bc.horiz,
380  horizup = vim.g.bc.horizup,
381  horizdown = vim.g.bc.horizdown,
382  vert = vim.g.bc.vert,
383  vertright = vim.g.bc.vertright,
384  vertleft = vim.g.bc.vertleft,
385  verthoriz = vim.g.bc.verthoriz,
386})
387
388vim.o.winborder = vim.g.border_style
389
390-- editor · cursor =============================================================
391
392vim.g.guicursor_config = {
393  normal = {
394    type = "block",
395  },
396  insert = {
397    type = "vertical",
398    size = 20,
399    animate = {
400      wait = 50,
401      on = 250,
402      off = 250,
403    },
404  },
405  replace = {
406    type = "horizontal",
407    size = 20,
408  },
409  operator = {
410    type = "horizontal",
411    size = 50,
412  },
413  showmatch = {
414    type = "block",
415  },
416}