diff options
Diffstat (limited to 'nvim.lua')
-rw-r--r-- | nvim.lua | 577 |
1 files changed, 577 insertions, 0 deletions
diff --git a/nvim.lua b/nvim.lua new file mode 100644 index 0000000..180e868 --- /dev/null +++ b/nvim.lua | |||
@@ -0,0 +1,577 @@ | |||
1 | --[[ | ||
2 | |||
3 | ===================================================================== | ||
4 | ==================== READ THIS BEFORE CONTINUING ==================== | ||
5 | ===================================================================== | ||
6 | |||
7 | Kickstart.nvim is *not* a distribution. | ||
8 | |||
9 | Kickstart.nvim is a template for your own configuration. | ||
10 | The goal is that you can read every line of code, top-to-bottom, understand | ||
11 | what your configuration is doing, and modify it to suit your needs. | ||
12 | |||
13 | Once you've done that, you should start exploring, configuring and tinkering to | ||
14 | explore Neovim! | ||
15 | |||
16 | If you don't know anything about Lua, I recommend taking some time to read through | ||
17 | a guide. One possible example: | ||
18 | - https://learnxinyminutes.com/docs/lua/ | ||
19 | |||
20 | |||
21 | And then you can explore or search through `:help lua-guide` | ||
22 | - https://neovim.io/doc/user/lua-guide.html | ||
23 | |||
24 | |||
25 | Kickstart Guide: | ||
26 | |||
27 | I have left several `:help X` comments throughout the init.lua | ||
28 | You should run that command and read that help section for more information. | ||
29 | |||
30 | In addition, I have some `NOTE:` items throughout the file. | ||
31 | These are for you, the reader to help understand what is happening. Feel free to delete | ||
32 | them once you know what you're doing, but they should serve as a guide for when you | ||
33 | are first encountering a few different constructs in your nvim config. | ||
34 | |||
35 | I hope you enjoy your Neovim journey, | ||
36 | - TJ | ||
37 | |||
38 | P.S. You can delete this when you're done too. It's your config now :) | ||
39 | --]] | ||
40 | |||
41 | -- Install package manager | ||
42 | -- https://github.com/folke/lazy.nvim | ||
43 | -- `:help lazy.nvim.txt` for more info | ||
44 | local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' | ||
45 | if not vim.loop.fs_stat(lazypath) then | ||
46 | vim.fn.system { | ||
47 | 'git', | ||
48 | 'clone', | ||
49 | '--filter=blob:none', | ||
50 | 'https://github.com/folke/lazy.nvim.git', | ||
51 | '--branch=stable', -- latest stable release | ||
52 | lazypath, | ||
53 | } | ||
54 | end | ||
55 | vim.opt.runtimepath:prepend(lazypath) | ||
56 | |||
57 | -- NOTE: Here is where you install your plugins. | ||
58 | -- You can configure plugins using the `config` key. | ||
59 | -- | ||
60 | -- You can also configure plugins after the setup call, | ||
61 | -- as they will be available in your neovim runtime. | ||
62 | require('lazy').setup({ | ||
63 | -- NOTE: First, some plugins that don't require any configuration | ||
64 | |||
65 | -- Git related plugins | ||
66 | 'tpope/vim-fugitive', | ||
67 | 'tpope/vim-rhubarb', | ||
68 | |||
69 | -- Detect tabstop and shiftwidth automatically | ||
70 | 'tpope/vim-sleuth', | ||
71 | |||
72 | -- Use sudo in command mode | ||
73 | 'lambdalisue/suda.vim', | ||
74 | |||
75 | -- For beancount | ||
76 | 'nathangrigg/vim-beancount', | ||
77 | |||
78 | -- For surrounding | ||
79 | 'machakann/vim-sandwich', | ||
80 | |||
81 | |||
82 | -- NOTE: This is where your plugins related to LSP can be installed. | ||
83 | -- The configuration is done below. Search for lspconfig to find it below. | ||
84 | { | ||
85 | -- LSP Configuration & Plugins | ||
86 | 'neovim/nvim-lspconfig', | ||
87 | dependencies = { | ||
88 | -- Automatically install LSPs to stdpath for neovim | ||
89 | { 'williamboman/mason.nvim', config = true }, | ||
90 | 'williamboman/mason-lspconfig.nvim', | ||
91 | |||
92 | -- Useful status updates for LSP | ||
93 | -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` | ||
94 | { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, | ||
95 | |||
96 | -- Additional lua configuration, makes nvim stuff amazing! | ||
97 | 'folke/neodev.nvim', | ||
98 | }, | ||
99 | }, | ||
100 | |||
101 | { | ||
102 | -- Autocompletion | ||
103 | 'hrsh7th/nvim-cmp', | ||
104 | dependencies = { | ||
105 | -- Snippet Engine & its associated nvim-cmp source | ||
106 | 'L3MON4D3/LuaSnip', | ||
107 | 'saadparwaiz1/cmp_luasnip', | ||
108 | |||
109 | -- Adds LSP completion capabilities | ||
110 | 'hrsh7th/cmp-nvim-lsp', | ||
111 | |||
112 | -- Adds a number of user-friendly snippets | ||
113 | 'rafamadriz/friendly-snippets', | ||
114 | }, | ||
115 | }, | ||
116 | |||
117 | -- Useful plugin to show you pending keybinds. | ||
118 | { 'folke/which-key.nvim', opts = {} }, | ||
119 | { | ||
120 | -- Adds git related signs to the gutter, as well as utilities for managing changes | ||
121 | 'lewis6991/gitsigns.nvim', | ||
122 | opts = { | ||
123 | -- See `:help gitsigns.txt` | ||
124 | signs = { | ||
125 | add = { text = '+' }, | ||
126 | change = { text = '~' }, | ||
127 | delete = { text = '_' }, | ||
128 | topdelete = { text = '‾' }, | ||
129 | changedelete = { text = '~' }, | ||
130 | }, | ||
131 | on_attach = function(bufnr) | ||
132 | vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, | ||
133 | { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) | ||
134 | vim.keymap.set('n', '<leader>gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) | ||
135 | vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) | ||
136 | end, | ||
137 | }, | ||
138 | }, | ||
139 | |||
140 | { | ||
141 | -- Theme inspired by Atom | ||
142 | 'navarasu/onedark.nvim', | ||
143 | priority = 1000, | ||
144 | config = function() | ||
145 | vim.cmd.colorscheme 'onedark' | ||
146 | end, | ||
147 | }, | ||
148 | |||
149 | { | ||
150 | -- Set lualine as statusline | ||
151 | 'nvim-lualine/lualine.nvim', | ||
152 | -- See `:help lualine.txt` | ||
153 | opts = { | ||
154 | options = { | ||
155 | icons_enabled = false, | ||
156 | theme = 'onedark', | ||
157 | component_separators = '|', | ||
158 | section_separators = { left = '', right = '' }, | ||
159 | }, | ||
160 | }, | ||
161 | }, | ||
162 | |||
163 | { | ||
164 | -- Add indentation guides even on blank lines | ||
165 | 'lukas-reineke/indent-blankline.nvim', | ||
166 | -- Enable `lukas-reineke/indent-blankline.nvim` | ||
167 | -- See `:help indent_blankline.txt` | ||
168 | opts = { | ||
169 | char = '┊', | ||
170 | show_trailing_blankline_indent = true, | ||
171 | }, | ||
172 | }, | ||
173 | |||
174 | -- "gc" to comment visual regions/lines | ||
175 | { 'numToStr/Comment.nvim', opts = {} }, | ||
176 | -- Another config | ||
177 | -- { | ||
178 | -- 'numToStr/Comment.nvim', | ||
179 | -- opts = { | ||
180 | -- opleader = { | ||
181 | -- ---Line-comment keymap | ||
182 | -- line = '<C-_>', | ||
183 | -- ---Block-comment keymap | ||
184 | -- block = 'gb', | ||
185 | -- }, | ||
186 | -- }, | ||
187 | |||
188 | |||
189 | -- Fuzzy Finder (files, lsp, etc) | ||
190 | { | ||
191 | 'nvim-telescope/telescope.nvim', | ||
192 | branch = '0.1.x', | ||
193 | dependencies = { | ||
194 | 'nvim-lua/plenary.nvim', | ||
195 | -- Fuzzy Finder Algorithm which requires local dependencies to be built. | ||
196 | -- Only load if `make` is available. Make sure you have the system | ||
197 | -- requirements installed. | ||
198 | { | ||
199 | 'nvim-telescope/telescope-fzf-native.nvim', | ||
200 | -- NOTE: If you are having trouble with this installation, | ||
201 | -- refer to the README for telescope-fzf-native for more instructions. | ||
202 | build = 'make', | ||
203 | cond = function() | ||
204 | return vim.fn.executable 'make' == 1 | ||
205 | end, | ||
206 | }, | ||
207 | }, | ||
208 | }, | ||
209 | |||
210 | { | ||
211 | -- Highlight, edit, and navigate code | ||
212 | 'nvim-treesitter/nvim-treesitter', | ||
213 | dependencies = { | ||
214 | 'nvim-treesitter/nvim-treesitter-textobjects', | ||
215 | }, | ||
216 | build = ':TSUpdate', | ||
217 | }, | ||
218 | |||
219 | -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart | ||
220 | -- These are some example plugins that I've included in the kickstart repository. | ||
221 | -- Uncomment any of the lines below to enable them. | ||
222 | -- require 'kickstart.plugins.autoformat', | ||
223 | -- require 'kickstart.plugins.debug', | ||
224 | |||
225 | -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` | ||
226 | -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping | ||
227 | -- up-to-date with whatever is in the kickstart repo. | ||
228 | -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. | ||
229 | -- | ||
230 | -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins | ||
231 | -- { import = 'custom.plugins' }, | ||
232 | }, {}) | ||
233 | |||
234 | -- [[ Setting options ]] | ||
235 | -- See `:help vim.o` | ||
236 | |||
237 | -- Sync clipboard between OS and Neovim. | ||
238 | -- Remove this option if you want your OS clipboard to remain independent. | ||
239 | -- See `:help 'clipboard'` | ||
240 | |||
241 | -- vim.o.clipboard = 'unnamedplus' | ||
242 | |||
243 | -- Enable break indent | ||
244 | vim.o.breakindent = true | ||
245 | |||
246 | -- Save undo history | ||
247 | vim.o.undofile = true | ||
248 | |||
249 | -- Case-insensitive searching UNLESS \C or capital in search | ||
250 | vim.o.ignorecase = true | ||
251 | vim.o.smartcase = true | ||
252 | |||
253 | -- Keep signcolumn on by default | ||
254 | vim.wo.signcolumn = 'yes' | ||
255 | |||
256 | -- Decrease update time | ||
257 | vim.o.updatetime = 250 | ||
258 | vim.o.timeout = true | ||
259 | vim.o.timeoutlen = 300 | ||
260 | |||
261 | -- Set completeopt to have a better completion experience | ||
262 | vim.o.completeopt = 'menuone,noselect' | ||
263 | |||
264 | -- NOTE: You should make sure your terminal supports this | ||
265 | vim.o.termguicolors = true | ||
266 | |||
267 | -- [[ Basic Keymaps ]] | ||
268 | |||
269 | -- Keymaps for better default experience | ||
270 | -- See `:help vim.keymap.set()` | ||
271 | vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) | ||
272 | |||
273 | -- Use suda.vim to run sudo, or terminal prompt fails | ||
274 | -- See more details at https://github.com/neovim/neovim/issue | ||
275 | vim.cmd("command! W execute 'SudaWrite %'") | ||
276 | |||
277 | |||
278 | -- [[ Configure lualine ]] | ||
279 | -- Change the background of lualine_b section for normal mode | ||
280 | local custom_wombat = require 'lualine.themes.wombat' | ||
281 | custom_wombat.normal.b.bg = '#a8a8a8' | ||
282 | custom_wombat.normal.b.fg = '#444444' | ||
283 | require('lualine').setup { | ||
284 | options = { theme = custom_wombat }, | ||
285 | } | ||
286 | |||
287 | -- [[ Highlight on yank ]] | ||
288 | -- See `:help vim.highlight.on_yank()` | ||
289 | local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | ||
290 | vim.api.nvim_create_autocmd('TextYankPost', { | ||
291 | callback = function() | ||
292 | vim.highlight.on_yank() | ||
293 | end, | ||
294 | group = highlight_group, | ||
295 | pattern = '*', | ||
296 | }) | ||
297 | |||
298 | -- [[ Configure Telescope ]] | ||
299 | -- See `:help telescope` and `:help telescope.setup()` | ||
300 | require('telescope').setup { | ||
301 | defaults = { | ||
302 | mappings = { | ||
303 | i = { | ||
304 | ['<C-u>'] = false, | ||
305 | ['<C-d>'] = false, | ||
306 | ["<c-j>"] = "move_selection_next", | ||
307 | ["<c-k>"] = "move_selection_previous", | ||
308 | }, | ||
309 | }, | ||
310 | layout_config = { | ||
311 | vertical = { height = 0.8 } | ||
312 | -- other layout configuration here | ||
313 | }, | ||
314 | }, | ||
315 | pickers = { | ||
316 | oldfiles = { | ||
317 | previewer = true, | ||
318 | }, | ||
319 | buffers = { | ||
320 | show_all_buffers = true, | ||
321 | sort_lastused = true, | ||
322 | theme = "dropdown", | ||
323 | previewer = false, | ||
324 | mappings = { | ||
325 | i = { | ||
326 | ["<c-d>"] = "delete_buffer", | ||
327 | }, | ||
328 | n = { | ||
329 | ["<c-d>"] = "delete_buffer", | ||
330 | } | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | -- Enable telescope fzf native, if installed | ||
337 | pcall(require('telescope').load_extension, 'fzf') | ||
338 | |||
339 | -- See `:help telescope.builtin` | ||
340 | vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[f] Find recently opened files' }) | ||
341 | vim.keymap.set('n', '<leader>q', require('telescope.builtin').buffers, { desc = '[q] Find existing buffers' }) | ||
342 | vim.keymap.set('n', '<leader>/', function() | ||
343 | -- You can pass additional configuration to telescope to change theme, layout, etc. | ||
344 | require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { | ||
345 | --winblend = 10, | ||
346 | previewer = false, | ||
347 | }) | ||
348 | end, { desc = '[/] Fuzzily search in current buffer' }) | ||
349 | |||
350 | vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) | ||
351 | vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) | ||
352 | vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) | ||
353 | vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) | ||
354 | vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) | ||
355 | vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) | ||
356 | |||
357 | -- [[ Configure Treesitter ]] | ||
358 | -- See `:help nvim-treesitter` | ||
359 | require('nvim-treesitter.configs').setup { | ||
360 | -- Add languages to be installed here that you want installed for treesitter | ||
361 | ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, | ||
362 | |||
363 | -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) | ||
364 | auto_install = false, | ||
365 | |||
366 | highlight = { enable = true }, | ||
367 | indent = { enable = true }, | ||
368 | incremental_selection = { | ||
369 | enable = true, | ||
370 | keymaps = { | ||
371 | init_selection = '<c-space>', | ||
372 | node_incremental = '<c-space>', | ||
373 | scope_incremental = '<c-s>', | ||
374 | node_decremental = '<M-space>', | ||
375 | }, | ||
376 | }, | ||
377 | textobjects = { | ||
378 | select = { | ||
379 | enable = true, | ||
380 | lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim | ||
381 | keymaps = { | ||
382 | -- You can use the capture groups defined in textobjects.scm | ||
383 | ['aa'] = '@parameter.outer', | ||
384 | ['ia'] = '@parameter.inner', | ||
385 | ['af'] = '@function.outer', | ||
386 | ['if'] = '@function.inner', | ||
387 | ['ac'] = '@class.outer', | ||
388 | ['ic'] = '@class.inner', | ||
389 | }, | ||
390 | }, | ||
391 | move = { | ||
392 | enable = true, | ||
393 | set_jumps = true, -- whether to set jumps in the jumplist | ||
394 | goto_next_start = { | ||
395 | [']m'] = '@function.outer', | ||
396 | [']]'] = '@class.outer', | ||
397 | }, | ||
398 | goto_next_end = { | ||
399 | [']M'] = '@function.outer', | ||
400 | [']['] = '@class.outer', | ||
401 | }, | ||
402 | goto_previous_start = { | ||
403 | ['[m'] = '@function.outer', | ||
404 | ['[['] = '@class.outer', | ||
405 | }, | ||
406 | goto_previous_end = { | ||
407 | ['[M'] = '@function.outer', | ||
408 | ['[]'] = '@class.outer', | ||
409 | }, | ||
410 | }, | ||
411 | swap = { | ||
412 | enable = true, | ||
413 | swap_next = { | ||
414 | ['<leader>a'] = '@parameter.inner', | ||
415 | }, | ||
416 | swap_previous = { | ||
417 | ['<leader>A'] = '@parameter.inner', | ||
418 | }, | ||
419 | }, | ||
420 | }, | ||
421 | } | ||
422 | |||
423 | -- Diagnostic keymaps | ||
424 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) | ||
425 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) | ||
426 | vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) | ||
427 | vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) | ||
428 | |||
429 | -- [[ Configure LSP ]] | ||
430 | -- This function gets run when an LSP connects to a particular buffer. | ||
431 | local on_attach = function(_, bufnr) | ||
432 | -- NOTE: Remember that lua is a real programming language, and as such it is possible | ||
433 | -- to define small helper and utility functions so you don't have to repeat yourself | ||
434 | -- many times. | ||
435 | -- | ||
436 | -- In this case, we create a function that lets us more easily define mappings specific | ||
437 | -- for LSP related items. It sets the mode, buffer and description for us each time. | ||
438 | local nmap = function(keys, func, desc) | ||
439 | if desc then | ||
440 | desc = 'LSP: ' .. desc | ||
441 | end | ||
442 | |||
443 | vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) | ||
444 | end | ||
445 | |||
446 | nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') | ||
447 | nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') | ||
448 | |||
449 | nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') | ||
450 | nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') | ||
451 | nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') | ||
452 | nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') | ||
453 | nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') | ||
454 | nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') | ||
455 | |||
456 | -- See `:help K` for why this keymap | ||
457 | nmap('K', vim.lsp.buf.hover, 'Hover Documentation') | ||
458 | nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') | ||
459 | |||
460 | -- Lesser used LSP functionality | ||
461 | nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') | ||
462 | nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') | ||
463 | nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') | ||
464 | nmap('<leader>wl', function() | ||
465 | print(vim.inspect(vim.lsp.buf.list_workspace_folders())) | ||
466 | end, '[W]orkspace [L]ist Folders') | ||
467 | |||
468 | -- Create a command `:Format` local to the LSP buffer | ||
469 | vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) | ||
470 | vim.lsp.buf.format() | ||
471 | end, { desc = 'Format current buffer with LSP' }) | ||
472 | nmap('<leader>F', ':Format<CR>', 'Format code') | ||
473 | end | ||
474 | |||
475 | -- Enable the following language servers | ||
476 | -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. | ||
477 | -- | ||
478 | -- Add any additional override configuration in the following tables. They will be passed to | ||
479 | -- the `settings` field of the server config. You must look up that documentation yourself. | ||
480 | -- | ||
481 | -- If you want to override the default filetypes that your language server will attach to you can | ||
482 | -- define the property 'filetypes' to the map in question. | ||
483 | local servers = { | ||
484 | -- clangd = {}, | ||
485 | -- gopls = {}, | ||
486 | -- pyright = {}, | ||
487 | -- rust_analyzer = {}, | ||
488 | -- tsserver = {}, | ||
489 | -- html = { filetypes = { 'html', 'twig', 'hbs'} }, | ||
490 | tsserver = {}, | ||
491 | beancount = { | ||
492 | filetypes = { "beancount", "bean" }, | ||
493 | }, | ||
494 | |||
495 | lua_ls = { | ||
496 | Lua = { | ||
497 | workspace = { checkThirdParty = false }, | ||
498 | telemetry = { enable = false }, | ||
499 | }, | ||
500 | }, | ||
501 | } | ||
502 | |||
503 | -- Setup neovim lua configuration | ||
504 | require('neodev').setup() | ||
505 | |||
506 | -- nvim-cmp supports additional completion capabilities, so broadcast that to servers | ||
507 | local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
508 | capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | ||
509 | |||
510 | -- Ensure the servers above are installed | ||
511 | local mason_lspconfig = require 'mason-lspconfig' | ||
512 | |||
513 | mason_lspconfig.setup { | ||
514 | ensure_installed = vim.tbl_keys(servers), | ||
515 | } | ||
516 | |||
517 | mason_lspconfig.setup_handlers { | ||
518 | function(server_name) | ||
519 | require('lspconfig')[server_name].setup { | ||
520 | capabilities = capabilities, | ||
521 | on_attach = on_attach, | ||
522 | settings = servers[server_name], | ||
523 | filetypes = (servers[server_name] or {}).filetypes, | ||
524 | } | ||
525 | end | ||
526 | } | ||
527 | |||
528 | -- [[ Configure nvim-cmp ]] | ||
529 | -- See `:help cmp` | ||
530 | local cmp = require 'cmp' | ||
531 | local luasnip = require 'luasnip' | ||
532 | require('luasnip.loaders.from_vscode').lazy_load() | ||
533 | luasnip.config.setup {} | ||
534 | |||
535 | cmp.setup { | ||
536 | snippet = { | ||
537 | expand = function(args) | ||
538 | luasnip.lsp_expand(args.body) | ||
539 | end, | ||
540 | }, | ||
541 | mapping = cmp.mapping.preset.insert { | ||
542 | ['<C-n>'] = cmp.mapping.select_next_item(), | ||
543 | ['<C-p>'] = cmp.mapping.select_prev_item(), | ||
544 | ['<C-d>'] = cmp.mapping.scroll_docs(-4), | ||
545 | ['<C-f>'] = cmp.mapping.scroll_docs(4), | ||
546 | ['<C-Space>'] = cmp.mapping.complete {}, | ||
547 | ['<CR>'] = cmp.mapping.confirm { | ||
548 | behavior = cmp.ConfirmBehavior.Replace, | ||
549 | select = true, | ||
550 | }, | ||
551 | ['<Tab>'] = cmp.mapping(function(fallback) | ||
552 | if cmp.visible() then | ||
553 | cmp.select_next_item() | ||
554 | elseif luasnip.expand_or_locally_jumpable() then | ||
555 | luasnip.expand_or_jump() | ||
556 | else | ||
557 | fallback() | ||
558 | end | ||
559 | end, { 'i', 's' }), | ||
560 | ['<S-Tab>'] = cmp.mapping(function(fallback) | ||
561 | if cmp.visible() then | ||
562 | cmp.select_prev_item() | ||
563 | elseif luasnip.locally_jumpable(-1) then | ||
564 | luasnip.jump(-1) | ||
565 | else | ||
566 | fallback() | ||
567 | end | ||
568 | end, { 'i', 's' }), | ||
569 | }, | ||
570 | sources = { | ||
571 | { name = 'nvim_lsp' }, | ||
572 | { name = 'luasnip' }, | ||
573 | }, | ||
574 | } | ||
575 | |||
576 | -- The line beneath this is called `modeline`. See `:help modeline` | ||
577 | -- vim: ts=2 sts=2 sw=2 et | ||