diff options
Diffstat (limited to 'dotfiles/vim/lua/myConfig.lua')
-rw-r--r-- | dotfiles/vim/lua/myConfig.lua | 495 |
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 | |||
4 | vim.o.undofile = true | ||
5 | vim.o.backup = true | ||
6 | vim.opt.backupdir:remove "." | ||
7 | |||
8 | vim.opt.shortmess:append "c" | ||
9 | |||
10 | vim.o.mouse = "a" | ||
11 | |||
12 | vim.o.ignorecase = true | ||
13 | vim.o.smartcase = true | ||
14 | |||
15 | vim.o.smartindent = true | ||
16 | -- TODO: check that | ||
17 | vim.o.cindent = true | ||
18 | |||
19 | -- tabstop and shiftwidth are also set locally by individual filetypes | ||
20 | |||
21 | vim.o.tabstop = 4 | ||
22 | vim.o.shiftwidth = 4 | ||
23 | |||
24 | vim.opt.shortmess:append "A" | ||
25 | |||
26 | vim.o.inccommand = "split" | ||
27 | |||
28 | vim.o.scrolloff = 1 | ||
29 | vim.o.sidescrolloff = 5 | ||
30 | |||
31 | vim.o.colorcolumn = "80" | ||
32 | vim.o.cursorline = true | ||
33 | |||
34 | vim.o.title = true | ||
35 | |||
36 | vim.opt.wildmode = { "longest:full", "full" } | ||
37 | vim.opt.completeopt = { "menu", "menuone", "preview", "noinsert", "noselect" } | ||
38 | |||
39 | -- Use ripgrep | ||
40 | vim.o.grepprg = vim.g.ripgrep_path .. " --vimgrep --smart-case" | ||
41 | vim.o.grepformat = "%f:%l:%c:%m," .. vim.o.grepformat | ||
42 | |||
43 | vim.o.termguicolors = true | ||
44 | vim.o.background = "dark" | ||
45 | |||
46 | vim.o.updatetime = 1000 | ||
47 | |||
48 | -- Mode already shown by the status line | ||
49 | vim.o.showmode = false | ||
50 | |||
51 | vim.opt.listchars = { | ||
52 | extends = ">", | ||
53 | nbsp = "+", | ||
54 | precedes = "<", | ||
55 | tab = " ", | ||
56 | trail = "-", | ||
57 | } | ||
58 | vim.wo.list = true | ||
59 | |||
60 | -- Leaders | ||
61 | ---------- | ||
62 | |||
63 | vim.g.maplocalleader = "," | ||
64 | vim.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 | |||
74 | local last_cursor_pos_augroup = vim.api.nvim_create_augroup("LastCursorPos", {}) | ||
75 | vim.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 | |||
115 | vim.api.nvim_create_autocmd("TextYankPost", { | ||
116 | desc = "Highlight yanked text", | ||
117 | callback = function(opts) | ||
118 | vim.highlight.on_yank() | ||
119 | end, | ||
120 | }) | ||
121 | |||
122 | vim.g.tex_flavor = "latex" | ||
123 | |||
124 | vim.g.gruvbox_italic = 1 | ||
125 | vim.cmd "colorscheme gruvbox" | ||
126 | |||
127 | -- Mappings | ||
128 | ----------- | ||
129 | |||
130 | local mapopts = { noremap = true, silent = true } | ||
131 | |||
132 | vim.fn["camelcasemotion#CreateMotionMappings"] "<LocalLeader>" | ||
133 | |||
134 | vim.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 | ||
142 | end, mapopts) | ||
143 | |||
144 | -- Plugins | ||
145 | ---------- | ||
146 | |||
147 | -- Impatient | ||
148 | |||
149 | require("impatient") | ||
150 | |||
151 | -- Gitsigns | ||
152 | |||
153 | require("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 | |||
177 | require("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 | |||
268 | vim.o.foldmethod = "expr" | ||
269 | vim.o.foldexpr = "nvim_treesitter#foldexpr()" | ||
270 | vim.o.foldlevel = 99 | ||
271 | |||
272 | vim.api.nvim_set_hl(0, "TSCurrentScope", { | ||
273 | bg = vim.g.current_gruvbox_colors.dark0_soft[1], | ||
274 | }) | ||
275 | |||
276 | vim.api.nvim_set_hl(0, "TSDefinition", { | ||
277 | bg = vim.g.current_gruvbox_colors.faded_blue[1], | ||
278 | }) | ||
279 | |||
280 | vim.api.nvim_set_hl(0, "TSDefinitionUsage", { | ||
281 | bg = vim.g.current_gruvbox_colors.faded_aqua[1], | ||
282 | }) | ||
283 | |||
284 | -- Treesitter highlight groups | ||
285 | |||
286 | vim.api.nvim_set_hl(0, "@attribute", { link = "Macro" }) | ||
287 | vim.api.nvim_set_hl(0, "@error", { link = "ErrorMsg" }) | ||
288 | |||
289 | vim.api.nvim_set_hl(0, "@text.diff.add", { link = "diffAdded" }) | ||
290 | vim.api.nvim_set_hl(0, "@text.diff.delete", { link = "diffRemoved" }) | ||
291 | |||
292 | vim.api.nvim_set_hl(0, "@text.strong", { bold = true }) | ||
293 | vim.api.nvim_set_hl(0, "@text.emphasis", { italic = true }) | ||
294 | vim.api.nvim_set_hl(0, "@text.underline", { underline = true }) | ||
295 | vim.api.nvim_set_hl(0, "@text.strike", { strikethrough = true }) | ||
296 | vim.api.nvim_set_hl(0, "@text.environment", { link = "Macro" }) | ||
297 | |||
298 | vim.api.nvim_set_hl(0, "@text.note", { link = "ModeMsg" }) | ||
299 | vim.api.nvim_set_hl(0, "@text.warning", { link = "WarningMsg" }) | ||
300 | vim.api.nvim_set_hl(0, "@text.warning", { link = "ErrorMsg" }) | ||
301 | |||
302 | vim.api.nvim_set_hl(0, "@tag.attribute", { link = "@attribute" }) | ||
303 | vim.api.nvim_set_hl(0, "@tag.delimiter", { link = "@punctuation.delimiter" }) | ||
304 | |||
305 | -- nvim-cmp | ||
306 | |||
307 | local cmp = require "cmp" | ||
308 | |||
309 | cmp.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 | |||
350 | require("telescope").setup { | ||
351 | extensions = { | ||
352 | ["ui-select"] = { | ||
353 | require("telescope.themes").get_dropdown(), | ||
354 | }, | ||
355 | }, | ||
356 | } | ||
357 | |||
358 | require("telescope").load_extension "ui-select" | ||
359 | |||
360 | local telescope_builtin = require("telescope.builtin") | ||
361 | |||
362 | vim.keymap.set("n", "<leader>fb", telescope_builtin.buffers, mapopts) | ||
363 | vim.keymap.set("n", "<leader>ff", telescope_builtin.find_files, mapopts) | ||
364 | vim.keymap.set("n", "<leader>fg", telescope_builtin.live_grep, mapopts) | ||
365 | vim.keymap.set("n", "<leader>fh", telescope_builtin.help_tags, mapopts) | ||
366 | vim.keymap.set("n", "<leader>fo", telescope_builtin.oldfiles, mapopts) | ||
367 | vim.keymap.set("n", "<leader>fs", telescope_builtin.spell_suggest, mapopts) | ||
368 | vim.keymap.set("n", "<leader>ft", telescope_builtin.treesitter, mapopts) | ||
369 | |||
370 | -- Oil.nvim | ||
371 | |||
372 | require("oil").setup() | ||
373 | |||
374 | vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" }) | ||
375 | |||
376 | -- Lualine | ||
377 | |||
378 | require("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 | |||
397 | vim.keymap.set("i", "<Tab>", "vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'", { silent = true, expr = true }) | ||
398 | vim.keymap.set("s", "<Tab>", "vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'", { silent = true, expr = true }) | ||
399 | |||
400 | vim.keymap.set( | ||
401 | "i", | ||
402 | "<S-Tab>", | ||
403 | "vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<Tab>'", | ||
404 | { silent = true, expr = true } | ||
405 | ) | ||
406 | vim.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) | ||
417 | vim.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 | |||
428 | require("diffview").setup { | ||
429 | use_icons = false, | ||
430 | enhanced_diff_hl = true, | ||
431 | } | ||
432 | |||
433 | -- Notify | ||
434 | |||
435 | vim.cmd [[highlight link NotifyERRORBorder DiagnosticError]] | ||
436 | vim.cmd [[highlight link NotifyERRORIcon DiagnosticError]] | ||
437 | vim.cmd [[highlight link NotifyERRORTitle DiagnosticError]] | ||
438 | |||
439 | vim.cmd [[highlight link NotifyWARNBorder DiagnosticWarn]] | ||
440 | vim.cmd [[highlight link NotifyWARNIcon DiagnosticWarn]] | ||
441 | vim.cmd [[highlight link NotifyWARNTitle DiagnosticWarn]] | ||
442 | |||
443 | vim.cmd [[highlight link NotifyINFOBorder DiagnosticInfo]] | ||
444 | vim.cmd [[highlight link NotifyINFOIcon DiagnosticInfo]] | ||
445 | vim.cmd [[highlight link NotifyINFOTitle DiagnosticInfo]] | ||
446 | |||
447 | vim.cmd [[highlight link NotifyDEBUGBorder DiagnosticHint]] | ||
448 | vim.cmd [[highlight link NotifyDEBUGIcon DiagnosticHint]] | ||
449 | vim.cmd [[highlight link NotifyDEBUGTitle DiagnosticHint]] | ||
450 | |||
451 | vim.cmd [[highlight link NotifyDEBUGBorder GruvboxPurple]] | ||
452 | vim.cmd [[highlight link NotifyDEBUGIcon GruvboxPurple]] | ||
453 | vim.cmd [[highlight link NotifyDEBUGTitle GruvboxPurple]] | ||
454 | |||
455 | require("notify").setup { stages = "static" } | ||
456 | |||
457 | vim.notify = require("notify") | ||
458 | |||
459 | -- Comment | ||
460 | |||
461 | require("Comment").setup {} | ||
462 | |||
463 | -- Indent Blankline | ||
464 | |||
465 | vim.api.nvim_set_hl(0, "IndentBlanklineContextChar", { | ||
466 | fg = vim.g.current_gruvbox_colors.aqua[1], | ||
467 | }) | ||
468 | |||
469 | require("indent_blankline").setup { | ||
470 | show_current_context = true, | ||
471 | show_current_context_start = true, | ||
472 | } | ||
473 | |||
474 | -- Local config | ||
475 | |||
476 | function 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 | ||
489 | end | ||
490 | |||
491 | vim.opt.runtimepath:append "~/.config/nvim" | ||
492 | |||
493 | if isModuleAvailable "local_config" then | ||
494 | require "local_config" | ||
495 | end | ||