|
| 1 | +-- Install lazy |
| 2 | +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" |
| 3 | +if not vim.loop.fs_stat(lazypath) then |
| 4 | + vim.fn.system({ |
| 5 | + "git", |
| 6 | + "clone", |
| 7 | + "--filter=blob:none", |
| 8 | + "https://github.com/folke/lazy.nvim.git", |
| 9 | + "--branch=stable", -- latest stable release |
| 10 | + lazypath, |
| 11 | + }) |
| 12 | +end |
| 13 | +vim.opt.rtp:prepend(lazypath) |
| 14 | + |
| 15 | +-- [[ Basic Keymaps ]] |
| 16 | +-- Set <space> as the leader key |
| 17 | +-- See `:help mapleader` |
| 18 | +-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) |
| 19 | +vim.g.mapleader = ' ' |
| 20 | +vim.g.maplocalleader = ' ' |
| 21 | + |
| 22 | +-- load plugins using lazy.nvim |
| 23 | +require('lazy').setup('plugins') |
| 24 | + |
| 25 | +-- load base |
| 26 | +require('base') |
| 27 | + |
| 28 | +-- Keymaps |
| 29 | +require('keymaps') |
| 30 | + |
| 31 | +-- Enable Comment.nvim |
| 32 | +require('Comment').setup() |
| 33 | + |
| 34 | +-- Enable `lukas-reineke/indent-blankline.nvim` |
| 35 | +-- See `:help indent_blankline.txt` |
| 36 | + |
| 37 | +-- [[ Configure Telescope ]] |
| 38 | +-- See `:help telescope` and `:help telescope.setup()` |
| 39 | +require('telescope').setup { |
| 40 | + defaults = { |
| 41 | + mappings = { |
| 42 | + i = { |
| 43 | + ['<C-u>'] = false, |
| 44 | + ['<C-d>'] = false, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | +} |
| 49 | + |
| 50 | +-- Enable telescope fzf native, if installed |
| 51 | +pcall(require('telescope').load_extension, 'fzf') |
| 52 | + |
| 53 | +-- See `:help telescope.builtin` |
| 54 | +vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) |
| 55 | +vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) |
| 56 | +vim.keymap.set('n', '<leader>/', function() |
| 57 | + -- You can pass additional configuration to telescope to change theme, layout, etc. |
| 58 | + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { |
| 59 | + winblend = 10, |
| 60 | + previewer = false, |
| 61 | + }) |
| 62 | +end, { desc = '[/] Fuzzily search in current buffer]' }) |
| 63 | + |
| 64 | +vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) |
| 65 | +vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) |
| 66 | +vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) |
| 67 | +vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) |
| 68 | +vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) |
| 69 | + |
| 70 | +-- Diagnostic keymaps |
| 71 | +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) |
| 72 | +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) |
| 73 | +vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) |
| 74 | +vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist) |
| 75 | + |
| 76 | +-- LSP settings. |
| 77 | +-- Setup mason so it can manage external tooling |
| 78 | +require('mason').setup() |
| 79 | + |
| 80 | +-- Ensure the servers above are installed |
| 81 | +local mason_lspconfig = require 'mason-lspconfig' |
| 82 | + |
| 83 | +-- This function gets run when an LSP connects to a particular buffer. |
| 84 | +local on_attach = function(_, bufnr) |
| 85 | + -- NOTE: Remember that lua is a real programming language, and as such it is possible |
| 86 | + -- to define small helper and utility functions so you don't have to repeat yourself |
| 87 | + -- many times. |
| 88 | + -- |
| 89 | + -- In this case, we create a function that lets us more easily define mappings specific |
| 90 | + -- for LSP related items. It sets the mode, buffer and description for us each time. |
| 91 | + local nmap = function(keys, func, desc) |
| 92 | + if desc then |
| 93 | + desc = 'LSP: ' .. desc |
| 94 | + end |
| 95 | + |
| 96 | + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) |
| 97 | + end |
| 98 | + |
| 99 | + nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') |
| 100 | + nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction') |
| 101 | + |
| 102 | + nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') |
| 103 | + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') |
| 104 | + nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') |
| 105 | + nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition') |
| 106 | + nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') |
| 107 | + nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') |
| 108 | + |
| 109 | + -- See `:help K` for why this keymap |
| 110 | + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') |
| 111 | + nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') |
| 112 | + |
| 113 | + -- Lesser used LSP functionality |
| 114 | + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') |
| 115 | + nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') |
| 116 | + nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') |
| 117 | + nmap('<leader>wl', function() |
| 118 | + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) |
| 119 | + end, '[W]orkspace [L]ist Folders') |
| 120 | + |
| 121 | + -- Create a command `:Format` local to the LSP buffer |
| 122 | + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) |
| 123 | + vim.lsp.buf.format() |
| 124 | + end, { desc = 'Format current buffer with LSP' }) |
| 125 | +end |
| 126 | + |
| 127 | +-- Enable the following language servers |
| 128 | +-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. |
| 129 | +-- |
| 130 | +-- Add any additional override configuration in the following tables. They will be passed to |
| 131 | +-- the `settings` field of the server config. You must look up that documentation yourself. |
| 132 | +local servers = { |
| 133 | + -- clangd = {}, |
| 134 | + -- gopls = {}, |
| 135 | + -- pyright = {}, |
| 136 | + -- rust_analyzer = {}, |
| 137 | + -- tsserver = {}, |
| 138 | + |
| 139 | + lua_ls = { |
| 140 | + Lua = { |
| 141 | + workspace = { checkThirdParty = false }, |
| 142 | + telemetry = { enable = false }, |
| 143 | + }, |
| 144 | + }, |
| 145 | +} |
| 146 | + |
| 147 | +-- Setup neovim lua configuration |
| 148 | +require('neodev').setup() |
| 149 | +-- |
| 150 | +-- nvim-cmp supports additional completion capabilities, so broadcast that to servers |
| 151 | +local capabilities = vim.lsp.protocol.make_client_capabilities() |
| 152 | +capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) |
| 153 | + |
| 154 | +mason_lspconfig.setup { |
| 155 | + ensure_installed = vim.tbl_keys(servers), |
| 156 | +} |
| 157 | + |
| 158 | +mason_lspconfig.setup_handlers { |
| 159 | + function(server_name) |
| 160 | + require('lspconfig')[server_name].setup { |
| 161 | + capabilities = capabilities, |
| 162 | + on_attach = on_attach, |
| 163 | + settings = servers[server_name], |
| 164 | + } |
| 165 | + end, |
| 166 | +} |
| 167 | + |
| 168 | +-- Turn on lsp status information |
| 169 | +require('fidget').setup() |
| 170 | + |
| 171 | +-- nvim-cmp setup |
| 172 | +local cmp = require 'cmp' |
| 173 | +local luasnip = require 'luasnip' |
| 174 | + |
| 175 | +cmp.setup { |
| 176 | + snippet = { |
| 177 | + expand = function(args) |
| 178 | + luasnip.lsp_expand(args.body) |
| 179 | + end, |
| 180 | + }, |
| 181 | + mapping = cmp.mapping.preset.insert { |
| 182 | + ['<C-d>'] = cmp.mapping.scroll_docs(-4), |
| 183 | + ['<C-f>'] = cmp.mapping.scroll_docs(4), |
| 184 | + ['<C-Space>'] = cmp.mapping.complete(), |
| 185 | + ['<CR>'] = cmp.mapping.confirm { |
| 186 | + behavior = cmp.ConfirmBehavior.Replace, |
| 187 | + select = true, |
| 188 | + }, |
| 189 | + ['<Tab>'] = cmp.mapping(function(fallback) |
| 190 | + if cmp.visible() then |
| 191 | + cmp.select_next_item() |
| 192 | + elseif luasnip.expand_or_jumpable() then |
| 193 | + luasnip.expand_or_jump() |
| 194 | + else |
| 195 | + fallback() |
| 196 | + end |
| 197 | + end, { 'i', 's' }), |
| 198 | + ['<S-Tab>'] = cmp.mapping(function(fallback) |
| 199 | + if cmp.visible() then |
| 200 | + cmp.select_prev_item() |
| 201 | + elseif luasnip.jumpable(-1) then |
| 202 | + luasnip.jump(-1) |
| 203 | + else |
| 204 | + fallback() |
| 205 | + end |
| 206 | + end, { 'i', 's' }), |
| 207 | + }, |
| 208 | + sources = { |
| 209 | + { name = 'nvim_lsp' }, |
| 210 | + { name = 'luasnip' }, |
| 211 | + }, |
| 212 | +} |
| 213 | + |
| 214 | +-- The line beneath this is called `modeline`. See `:help modeline` |
| 215 | +-- vim: ts=2 sts=2 sw=2 et |
0 commit comments