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