summaryrefslogtreecommitdiffstats
path: root/dotfiles/vim/lua/myConfig.lua
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2023-01-18 13:39:42 +0100
committerMinijackson <minijackson@riseup.net>2023-01-18 13:39:42 +0100
commitcfdb14cf768f2971f6efe2e333c620571f30fad1 (patch)
tree7cf802c821abd12bf47a336784d444791ced6f83 /dotfiles/vim/lua/myConfig.lua
parent087b8756a6113c78ae20ee00c96c38f5922287a0 (diff)
downloadnixos-config-reborn-cfdb14cf768f2971f6efe2e333c620571f30fad1.tar.gz
nixos-config-reborn-cfdb14cf768f2971f6efe2e333c620571f30fad1.zip
vim: refactor, allowing different files like ftplugin
Diffstat (limited to 'dotfiles/vim/lua/myConfig.lua')
-rw-r--r--dotfiles/vim/lua/myConfig.lua495
1 files changed, 495 insertions, 0 deletions
diff --git a/dotfiles/vim/lua/myConfig.lua b/dotfiles/vim/lua/myConfig.lua
new file mode 100644
index 0000000..58c6f6d
--- /dev/null
+++ b/dotfiles/vim/lua/myConfig.lua
@@ -0,0 +1,495 @@
1-- Options
2----------
3
4vim.o.undofile = true
5vim.o.backup = true
6vim.opt.backupdir:remove "."
7
8vim.opt.shortmess:append "c"
9
10vim.o.mouse = "a"
11
12vim.o.ignorecase = true
13vim.o.smartcase = true
14
15vim.o.smartindent = true
16-- TODO: check that
17vim.o.cindent = true
18
19-- tabstop and shiftwidth are also set locally by individual filetypes
20
21vim.o.tabstop = 4
22vim.o.shiftwidth = 4
23
24vim.opt.shortmess:append "A"
25
26vim.o.inccommand = "split"
27
28vim.o.scrolloff = 1
29vim.o.sidescrolloff = 5
30
31vim.o.colorcolumn = "80"
32vim.o.cursorline = true
33
34vim.o.title = true
35
36vim.opt.wildmode = { "longest:full", "full" }
37vim.opt.completeopt = { "menu", "menuone", "preview", "noinsert", "noselect" }
38
39-- Use ripgrep
40vim.o.grepprg = vim.g.ripgrep_path .. " --vimgrep --smart-case"
41vim.o.grepformat = "%f:%l:%c:%m," .. vim.o.grepformat
42
43vim.o.termguicolors = true
44vim.o.background = "dark"
45
46vim.o.updatetime = 1000
47
48-- Mode already shown by the status line
49vim.o.showmode = false
50
51vim.opt.listchars = {
52 extends = ">",
53 nbsp = "+",
54 precedes = "<",
55 tab = " ",
56 trail = "-",
57}
58vim.wo.list = true
59
60-- Leaders
61----------
62
63vim.g.maplocalleader = ","
64vim.g.mapleader = ";"
65
66-- Misc
67-------
68
69-- From neovim#14420
70-- Restores the position of previously opened files
71
72-- Inspired by: https://github.com/ethanholz/nvim-lastplace
73
74local last_cursor_pos_augroup = vim.api.nvim_create_augroup("LastCursorPos", {})
75vim.api.nvim_create_autocmd("BufReadPost", {
76 group = last_cursor_pos_augroup,
77 desc = "Restore the position of previously opened files",
78 callback = function(opts)
79 if vim.tbl_contains({ "quickfix", "nofile", "help" }, vim.bo.buftype) then
80 return
81 end
82
83 if vim.tbl_contains({ "gitcommit", "gitrebase", "svn", "hgcommit" }, vim.bo.filetype) then
84 return
85 end
86
87 -- If a line has already been specified on the command line, we are done
88 -- nvim file +num
89 if vim.fn.line "." > 1 then
90 return
91 end
92
93 -- If the last line is set and the less than the last line in the buffer
94 if vim.fn.line [['"]] > 0 and vim.fn.line [['"]] <= vim.fn.line "$" then
95 if vim.fn.line "w$" == vim.fn.line "$" then
96 -- if the last line in the current buffer is also the last line visible
97 -- in this window
98 vim.cmd [[normal! g`"]]
99 elseif vim.fn.line "$" - vim.fn.line [['"]] > ((vim.fn.line "w$" - vim.fn.line "w0") / 2) - 1 then
100 -- if we're not at the bottom of the file, center the cursor on the
101 -- screen after we make the jump
102 vim.cmd [[normal! g`"zz]]
103 else
104 -- otherwise, show as much context as we can by jumping to the end of
105 -- the file and then to the mark. If we pressed zz here, there would be
106 -- blank lines at the bottom of the screen. We intentionally leave the
107 -- last line blank by pressing <c-e> so the user has a clue that they
108 -- are near the end of the file.
109 vim.cmd [[normal! G'"<c-e>]]
110 end
111 end
112 end,
113})
114
115vim.api.nvim_create_autocmd("TextYankPost", {
116 desc = "Highlight yanked text",
117 callback = function(opts)
118 vim.highlight.on_yank()
119 end,
120})
121
122vim.g.tex_flavor = "latex"
123
124vim.g.gruvbox_italic = 1
125vim.cmd "colorscheme gruvbox"
126
127-- Mappings
128-----------
129
130local mapopts = { noremap = true, silent = true }
131
132vim.fn["camelcasemotion#CreateMotionMappings"] "<LocalLeader>"
133
134vim.keymap.set("n", "yof", function()
135 if vim.opt_local.formatoptions:get().a then
136 vim.opt_local.formatoptions:remove "a"
137 print ":setlocal formatoptions-=a"
138 else
139 vim.opt_local.formatoptions:append "a"
140 print ":setlocal formatoptions+=a"
141 end
142end, mapopts)
143
144-- Plugins
145----------
146
147-- Impatient
148
149require("impatient")
150
151-- Gitsigns
152
153require("gitsigns").setup {
154 keymaps = {
155 noremap = true,
156 buffer = true,
157 silent = true,
158
159 ["n ]c"] = { expr = true, "&diff ? ']c' : '<cmd>lua require\"gitsigns\".next_hunk()<CR>'" },
160 ["n [c"] = { expr = true, "&diff ? '[c' : '<cmd>lua require\"gitsigns\".prev_hunk()<CR>'" },
161
162 ["n <leader>hs"] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
163 ["n <leader>hu"] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
164 ["n <leader>hr"] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
165 ["n <leader>hR"] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
166 ["n <leader>hp"] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
167 ["n <leader>hb"] = '<cmd>lua require"gitsigns".blame_line()<CR>',
168
169 -- Text objects
170 ["o ih"] = ':<C-U>lua require"gitsigns".select_hunk()<CR>',
171 ["x ih"] = ':<C-U>lua require"gitsigns".select_hunk()<CR>',
172 },
173}
174
175-- Treesitter
176
177require("nvim-treesitter.configs").setup {
178 parser_install_dir = vim.fn.stdpath("data") .. "/site",
179 highlight = {
180 enable = true,
181 },
182 incremental_selection = {
183 enable = true,
184 keymaps = {
185 init_selection = "gnn",
186 node_incremental = "grn",
187 scope_incremental = "grc",
188 node_decremental = "grm",
189 },
190 },
191 indent = {
192 enable = true,
193 disable = { "rust" },
194 },
195 matchup = {
196 enable = true,
197 },
198 refactor = {
199 highlight_definitions = { enable = true },
200 navigation = { enable = true },
201 },
202 textobjects = {
203 lsp_interop = {
204 enable = true,
205 border = "none",
206 peek_definition_code = {
207 ["<leader>df"] = "@function.outer",
208 ["<leader>dF"] = "@class.outer",
209 },
210 },
211
212 move = {
213 enable = true,
214 goto_next_start = {
215 ["]m"] = "@function.outer",
216 ["]]"] = "@class.outer",
217 },
218 goto_next_end = {
219 ["]M"] = "@function.outer",
220 ["]["] = "@class.outer",
221 },
222 goto_previous_start = {
223 ["[m"] = "@function.outer",
224 ["[["] = "@class.outer",
225 },
226 goto_previous_end = {
227 ["[M"] = "@function.outer",
228 ["[]"] = "@class.outer",
229 },
230 },
231
232 select = {
233 enable = true,
234 keymaps = {
235 -- You can use the capture groups defined in textobjects.scm
236 ["af"] = "@function.outer",
237 ["if"] = "@function.inner",
238
239 ["aF"] = "@call.outer",
240 ["iF"] = "@call.inner",
241
242 ["ac"] = "@class.outer",
243 ["ic"] = "@class.inner",
244
245 ["aC"] = "@comment.outer",
246 ["iC"] = "@comment.inner",
247
248 ["ab"] = "@block.outer",
249 ["ib"] = "@block.inner",
250
251 ["aa"] = "@parameter.outer",
252 ["ia"] = "@parameter.inner",
253 },
254 },
255
256 swap = {
257 enable = true,
258 swap_next = {
259 ["<leader>a"] = "@parameter.inner",
260 },
261 swap_previous = {
262 ["<leader>A"] = "@parameter.inner",
263 },
264 },
265 },
266}
267
268vim.o.foldmethod = "expr"
269vim.o.foldexpr = "nvim_treesitter#foldexpr()"
270vim.o.foldlevel = 99
271
272vim.api.nvim_set_hl(0, "TSCurrentScope", {
273 bg = vim.g.current_gruvbox_colors.dark0_soft[1],
274})
275
276vim.api.nvim_set_hl(0, "TSDefinition", {
277 bg = vim.g.current_gruvbox_colors.faded_blue[1],
278})
279
280vim.api.nvim_set_hl(0, "TSDefinitionUsage", {
281 bg = vim.g.current_gruvbox_colors.faded_aqua[1],
282})
283
284-- Treesitter highlight groups
285
286vim.api.nvim_set_hl(0, "@attribute", { link = "Macro" })
287vim.api.nvim_set_hl(0, "@error", { link = "ErrorMsg" })
288
289vim.api.nvim_set_hl(0, "@text.diff.add", { link = "diffAdded" })
290vim.api.nvim_set_hl(0, "@text.diff.delete", { link = "diffRemoved" })
291
292vim.api.nvim_set_hl(0, "@text.strong", { bold = true })
293vim.api.nvim_set_hl(0, "@text.emphasis", { italic = true })
294vim.api.nvim_set_hl(0, "@text.underline", { underline = true })
295vim.api.nvim_set_hl(0, "@text.strike", { strikethrough = true })
296vim.api.nvim_set_hl(0, "@text.environment", { link = "Macro" })
297
298vim.api.nvim_set_hl(0, "@text.note", { link = "ModeMsg" })
299vim.api.nvim_set_hl(0, "@text.warning", { link = "WarningMsg" })
300vim.api.nvim_set_hl(0, "@text.warning", { link = "ErrorMsg" })
301
302vim.api.nvim_set_hl(0, "@tag.attribute", { link = "@attribute" })
303vim.api.nvim_set_hl(0, "@tag.delimiter", { link = "@punctuation.delimiter" })
304
305-- nvim-cmp
306
307local cmp = require "cmp"
308
309cmp.setup {
310 snippet = {
311 expand = function(args)
312 vim.fn["vsnip#anonymous"](args.body)
313 end,
314 },
315 mapping = cmp.mapping.preset.insert {
316 ["<CR>"] = cmp.mapping.confirm { select = false },
317 },
318 sources = cmp.config.sources({
319 { name = "nvim_lsp" },
320 { name = "vsnip" },
321 { name = "latex_symbols" },
322 { name = "calc" },
323 }, {
324 { name = "path" },
325 { name = "treesitter" },
326 }, {
327 { name = "tmux" },
328 { name = "spell" },
329 -- Use \k for iskeyword because of UTF-8
330 { name = "buffer", option = { keyword_pattern = [[\k\+]] } },
331 }),
332}
333
334-- cmp.setup.cmdline("/", {
335-- sources = {
336-- { name = "buffer", option = { keyword_pattern = [[\k\+]] } },
337-- },
338-- mapping = cmp.mapping.preset.cmdline {},
339-- })
340
341-- cmp.setup.cmdline(":", {
342-- sources = cmp.config.sources {
343-- { name = "cmdline" },
344-- },
345-- mapping = cmp.mapping.preset.cmdline {},
346-- })
347
348-- Telescope
349
350require("telescope").setup {
351 extensions = {
352 ["ui-select"] = {
353 require("telescope.themes").get_dropdown(),
354 },
355 },
356}
357
358require("telescope").load_extension "ui-select"
359
360local telescope_builtin = require("telescope.builtin")
361
362vim.keymap.set("n", "<leader>fb", telescope_builtin.buffers, mapopts)
363vim.keymap.set("n", "<leader>ff", telescope_builtin.find_files, mapopts)
364vim.keymap.set("n", "<leader>fg", telescope_builtin.live_grep, mapopts)
365vim.keymap.set("n", "<leader>fh", telescope_builtin.help_tags, mapopts)
366vim.keymap.set("n", "<leader>fo", telescope_builtin.oldfiles, mapopts)
367vim.keymap.set("n", "<leader>fs", telescope_builtin.spell_suggest, mapopts)
368vim.keymap.set("n", "<leader>ft", telescope_builtin.treesitter, mapopts)
369
370-- Oil.nvim
371
372require("oil").setup()
373
374vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" })
375
376-- Lualine
377
378require("lualine").setup {
379 options = {
380 component_separators = "",
381 icons_enabled = false,
382 section_separators = "",
383 },
384 sections = {
385 lualine_c = {
386 "filename",
387 {
388 "lsp_progress",
389 display_components = { "lsp_client_name", { "title", "percentage", "message" } },
390 },
391 },
392 },
393}
394
395-- VSnip
396
397vim.keymap.set("i", "<Tab>", "vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'", { silent = true, expr = true })
398vim.keymap.set("s", "<Tab>", "vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'", { silent = true, expr = true })
399
400vim.keymap.set(
401 "i",
402 "<S-Tab>",
403 "vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<Tab>'",
404 { silent = true, expr = true }
405)
406vim.keymap.set(
407 "s",
408 "<S-Tab>",
409 "vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<Tab>'",
410 { silent = true, expr = true }
411)
412
413-- OSCyank
414
415-- Text yanked into the "t register gets copied using OSC52 escape sequences
416-- (e.g. goes through SSH)
417vim.api.nvim_create_autocmd("TextYankPost", {
418 desc = "Setup for OSCYank",
419 callback = function(opts)
420 if vim.v.event.regname == "t" then
421 vim.cmd [[OSCYankReg t]]
422 end
423 end,
424})
425
426-- Diffview
427
428require("diffview").setup {
429 use_icons = false,
430 enhanced_diff_hl = true,
431}
432
433-- Notify
434
435vim.cmd [[highlight link NotifyERRORBorder DiagnosticError]]
436vim.cmd [[highlight link NotifyERRORIcon DiagnosticError]]
437vim.cmd [[highlight link NotifyERRORTitle DiagnosticError]]
438
439vim.cmd [[highlight link NotifyWARNBorder DiagnosticWarn]]
440vim.cmd [[highlight link NotifyWARNIcon DiagnosticWarn]]
441vim.cmd [[highlight link NotifyWARNTitle DiagnosticWarn]]
442
443vim.cmd [[highlight link NotifyINFOBorder DiagnosticInfo]]
444vim.cmd [[highlight link NotifyINFOIcon DiagnosticInfo]]
445vim.cmd [[highlight link NotifyINFOTitle DiagnosticInfo]]
446
447vim.cmd [[highlight link NotifyDEBUGBorder DiagnosticHint]]
448vim.cmd [[highlight link NotifyDEBUGIcon DiagnosticHint]]
449vim.cmd [[highlight link NotifyDEBUGTitle DiagnosticHint]]
450
451vim.cmd [[highlight link NotifyDEBUGBorder GruvboxPurple]]
452vim.cmd [[highlight link NotifyDEBUGIcon GruvboxPurple]]
453vim.cmd [[highlight link NotifyDEBUGTitle GruvboxPurple]]
454
455require("notify").setup { stages = "static" }
456
457vim.notify = require("notify")
458
459-- Comment
460
461require("Comment").setup {}
462
463-- Indent Blankline
464
465vim.api.nvim_set_hl(0, "IndentBlanklineContextChar", {
466 fg = vim.g.current_gruvbox_colors.aqua[1],
467})
468
469require("indent_blankline").setup {
470 show_current_context = true,
471 show_current_context_start = true,
472}
473
474-- Local config
475
476function isModuleAvailable(name)
477 if package.loaded[name] then
478 return true
479 else
480 for _, searcher in ipairs(package.searchers or package.loaders) do
481 local loader = searcher(name)
482 if type(loader) == "function" then
483 package.preload[name] = loader
484 return true
485 end
486 end
487 return false
488 end
489end
490
491vim.opt.runtimepath:append "~/.config/nvim"
492
493if isModuleAvailable "local_config" then
494 require "local_config"
495end