config/nvim/init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' vim.opt.tabstop = 4 vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.autoindent = true vim.opt.background = 'dark' vim.opt.relativenumber = true vim.opt.mouse = 'a' vim.g.copilot_enabled = 0 -- vim.opt.clipboard = 'unnamedplus' vim.opt.undofile = true vim.opt.signcolumn = 'yes' -- vim.opt.foldenable = true -- vim.opt.foldmethod = "indent" -- by default split to the right/below vim.opt.splitright = true vim.opt.splitbelow = true vim.cmd.colorscheme 'habamax' vim.opt.cursorline = true vim.opt.scrolloff = 10 vim.opt.hlsearch = true vim.opt.list = true vim.keymap.set('n', '<leader>m', '<cmd>nohlsearch<CR>') vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- vim.opt.wildmenu = true -- vim.opt.showmatch = true -- vim.opt.incsearch = true -- vim.opt.numberwidth = 4 vim.opt.foldenable = true vim.opt.foldmethod = 'indent' vim.opt.foldlevelstart = 10 vim.opt.foldnestmax = 10 vim.opt.backspace = 'indent,eol,start' vim.opt.termguicolors = true -- Navigation keymaps vim.keymap.set('i', 'jk', '<Esc>') -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Previous [D]iagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Previous [D]iagnostic message' }) vim.keymap.set('n', 'gl', vim.diagnostic.open_float, { desc = 'Show diagnostic' }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -- Diagnostics config local signs = { { name = 'DiagnosticSignError', text = '' }, { name = 'DiagnosticSignWarn', text = '' }, { name = 'DiagnosticSignHint', text = '' }, { name = 'DiagnosticSignInfo', text = '' }, } for _, sign in ipairs(signs) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = '' }) end local config = { virtual_text = false, signs = { active = signs, }, update_in_insert = true, underline = true, severity_sort = true, float = { focusable = false, style = 'minimal', border = 'none', -- max_width = 80, source = 'always', header = '', prefix = '', }, } vim.diagnostic.config(config) -- Window keymaps -- See `:help wincmd` for a list of all window commands vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' }) vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' }) vim.keymap.set('n', 'j', 'gj') vim.keymap.set('n', 'k', 'gk') -- tab navigation vim.keymap.set('n', 'H', 'gT') vim.keymap.set('n', 'L', 'gt') -- folds vim.keymap.set('n', '<leader>l', 'za', { desc = 'fold' }) -- copy to clipbaord in visual mode vim.keymap.set('v', '<C-c>', '"+y') -- move blocvim.keymap.sets of text visually vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv") vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv") -- stay in visual mode while indenting vim.keymap.set('v', '>', '>gv') vim.keymap.set('v', '<', '<gv') vim.keymap.set('n', 'n', 'nzz') vim.keymap.set('n', '<C-d>', '<C-d>zz') vim.keymap.set('n', '<C-u>', '<C-u>zz') -- Launches vim.keymap.set('n', '<leader>g', ':Neogit<cr>') local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) require('lazy').setup { { 'tpope/vim-sleuth', enabled = false }, { 'numToStr/Comment.nvim', opts = {} }, { 'lewis6991/gitsigns.nvim', opts = { signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, }, }, { 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' enabled = false, config = function() -- This is the function that runs, AFTER loading require('which-key').setup() -- Document existing key chains require('which-key').register { ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' }, ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' }, ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' }, ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, ['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, ['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, } -- visual mode require('which-key').register({ ['<leader>h'] = { 'Git [H]unk' }, }, { mode = 'v' }) end, }, { 'nvim-telescope/telescope.nvim', event = 'VimEnter', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', { -- If encountering errors, see telescope-fzf-native README for installation instructions 'nvim-telescope/telescope-fzf-native.nvim', -- `build` is used to run some command when the plugin is installed/updated. -- This is only run then, not every time Neovim starts up. build = 'make', -- `cond` is a condition used to determine whether this plugin should be -- installed and loaded. cond = function() return vim.fn.executable 'make' == 1 end, }, -- TODO -- Test later -- { 'nvim-telescope/telescope-ui-select.nvim' }, { 'nvim-tree/nvim-web-devicons' }, }, config = function() require('telescope').setup { pickers = {}, defaults = { mappings = { i = { ['<Esc>'] = require('telescope.actions').close, ['<C-j>'] = require('telescope.actions').move_selection_next, ['<C-k>'] = require('telescope.actions').move_selection_previous, }, }, }, } pcall(require('telescope').load_extension, 'fzf') local builtin = require 'telescope.builtin' vim.keymap.set('n', '<C-_>', builtin.find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', '<leader>f', builtin.live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '<leader>b', builtin.buffers, { desc = 'Find existing buffers' }) vim.keymap.set('n', '<leader>sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) end, }, { 'neovim/nvim-lspconfig', dependencies = { { 'williamboman/mason.nvim', config = true }, 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', { 'folke/neodev.nvim', opts = {} }, }, config = function() vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('lsp-attach-group', { clear = true }), callback = function(event) local map = function(keys, func, desc) vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') map('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') map('K', vim.lsp.buf.hover, 'Hover Documentation') map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- The following two autocommands are used to highlight references of the -- word under your cursor when your cursor rests there for a little while. -- See `:help CursorHold` for information about when this is executed -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client.server_capabilities.documentHighlightProvider then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) vim.api.nvim_create_autocmd('LspDetach', { group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } end, }) end end, }) local capabilities = vim.lsp.protocol.make_client_capabilities() -- capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) local servers = { pyright = {}, ruff = {}, gopls = {}, jsonls = {}, terraformls = {}, tsserver = {}, -- ccls = {}, lua_ls = {}, } require('mason').setup() -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } require('mason-lspconfig').setup { handlers = { function(server_name) local server = servers[server_name] or {} -- This handles overriding only values explicitly passed -- by the server configuration above. Useful when disabling -- certain features of an LSP (for example, turning off formatting for tsserver) server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) require('lspconfig')[server_name].setup(server) end, }, } end, }, { -- Autoformat 'stevearc/conform.nvim', lazy = false, keys = { { '<leader>]', function() require('conform').format { async = true, lsp_fallback = true } end, mode = '', desc = '[F]ormat buffer', }, }, opts = { -- notify_on_error = false, format_on_save = function(bufnr) -- Disable "format_on_save lsp_fallback" for languages that don't -- have a well standardized coding style. You can add additional -- languages here or re-enable it for the disabled ones. local disable_filetypes = { c = true, cpp = true } return { timeout_ms = 500, lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], } end, formatters_by_ft = { lua = { 'stylua' }, python = { 'isort', 'black' }, -- You can use a sub-list to tell conform to run *until* a formatter -- is found. -- javascript = { { "prettierd", "prettier" } }, }, }, }, { -- Autocompletion 'hrsh7th/nvim-cmp', event = 'InsertEnter', dependencies = { -- Snippet Engine & its associated nvim-cmp source { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp', dependencies = { { 'rafamadriz/friendly-snippets', config = function() require('luasnip.loaders.from_vscode').lazy_load() require 'snippets' end, }, }, }, 'saadparwaiz1/cmp_luasnip', -- Adds other completion capabilities. -- nvim-cmp does not ship with all sources by default. They are split -- into multiple repos for maintenance purposes. 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', }, config = function() -- See `:help cmp` local cmp = require 'cmp' local luasnip = require 'luasnip' luasnip.config.setup {} local kind_icons = { Text = '', Method = 'm', Function = '', Constructor = '', Field = '', Variable = '', Class = '', Interface = '', Module = '', Property = '', Unit = '', Value = '', Enum = '', Keyword = '', Snippet = '', Color = '', File = '', Reference = '', Folder = '', EnumMember = '', Constant = '', Struct = '', Event = '', Operator = '', TypeParameter = '', } cmp.setup { snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, completion = { completeopt = 'menu,menuone,noinsert' }, -- For an understanding of why these mappings were -- chosen, you will need to read `:help ins-completion` -- -- No, but seriously. Please read `:help ins-completion`, it is really good! mapping = cmp.mapping.preset.insert { ['<C-j>'] = cmp.mapping.select_next_item(), ['<C-k>'] = cmp.mapping.select_prev_item(), ['<C-b>'] = cmp.mapping.scroll_docs(-4), ['<C-f>'] = cmp.mapping.scroll_docs(4), ['<CR>'] = cmp.mapping.confirm { select = true }, ['<C-Space>'] = cmp.mapping.complete {}, -- Think of <c-l> as moving to the right of your snippet expansion. -- So if you have a snippet that's like: -- function $name($args) -- $body -- end -- -- <c-l> will move you to the right of each of the expansion locations. -- <c-h> is similar, except moving you backwards. ['<C-l>'] = cmp.mapping(function() if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() end end, { 'i', 's' }), ['<C-h>'] = cmp.mapping(function() if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end end, { 'i', 's' }), -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, formatting = { fields = { 'kind', 'abbr', 'menu' }, expandable_indicator = true, format = function(entry, vim_item) -- Kind icons vim_item.kind = string.format('%s', kind_icons[vim_item.kind]) -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind vim_item.menu = ({ nvim_lsp = '[LSP]', luasnip = '[Snippet]', buffer = '[Buffer]', path = '[Path]', })[entry.source.name] return vim_item end, }, sources = { { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, }, } end, }, { 'echasnovski/mini.nvim', config = function() -- Examples: -- - va) - [V]isually select [A]round [)]paren -- - yinq - [Y]ank [I]nside [N]ext [']quote -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } -- Add/delete/replace surroundings (brackets, quotes, etc.) -- -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren -- - sd' - [S]urround [D]elete [']quotes -- - sr)' - [S]urround [R]eplace [)] ['] require('mini.surround').setup() -- Simple and easy statusline. -- You could remove this setup call if you don't like it, -- and try some other statusline plugin -- local statusline = require 'mini.statusline' -- set use_icons to true if you have a Nerd Font -- statusline.setup { use_icons = true } -- You can configure sections in the statusline by overriding their -- default behavior. For example, here we set the section for -- cursor location to LINE:COLUMN ---@diagnostic disable-next-line: duplicate-set-field -- statusline.section_location = function() -- return '%2l:%-2v' -- end -- Check out: https://github.com/echasnovski/mini.nvim end, }, { 'nyoom-engineering/oxocarbon.nvim', config = function() vim.cmd.colorscheme 'oxocarbon' end, }, require 'plugins.nvimtree', require 'plugins.neogit', require 'plugins.lint', { 'github/copilot.vim' }, } -- Need to test -- vim.opt.ignorecase = true -- vim.opt.smartcase = true -- vim.opt.breakindent = true -- vim.opt.updatetime = 250 -- vim.opt.list = true -- vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }