2 vim.g.maplocalleader = ' '
4 -- Install package manager
5 -- https://github.com/folke/lazy.nvim
6 -- `:help lazy.nvim.txt` for more info
7 local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
8 if not vim.loop.fs_stat(lazypath) then
13 'https://github.com/folke/lazy.nvim.git',
14 '--branch=stable', -- latest stable release
18 vim.opt.rtp:prepend(lazypath)
20 require('lazy').setup({
21 -- NOTE: First, some plugins that don't require any configuration
23 -- Git related plugins
27 -- Detect tabstop and shiftwidth automatically
30 -- NOTE: This is where your plugins related to LSP can be installed.
31 -- The configuration is done below. Search for lspconfig to find it below.
33 -- LSP Configuration & Plugins
34 'neovim/nvim-lspconfig',
36 -- Automatically install LSPs to stdpath for neovim
37 { 'williamboman/mason.nvim', config = true },
38 'williamboman/mason-lspconfig.nvim',
40 -- Useful status updates for LSP
41 -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
42 { 'j-hui/fidget.nvim', opts = {}, tag = 'legacy' },
44 -- Additional lua configuration, makes nvim stuff amazing!
52 dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip',
53 'rafamadriz/friendly-snippets' },
56 -- Useful plugin to show you pending keybinds.
57 { 'folke/which-key.nvim', opts = {} },
59 -- Adds git releated signs to the gutter, as well as utilities for managing changes
60 'lewis6991/gitsigns.nvim',
62 -- See `:help gitsigns.txt`
65 change = { text = '~' },
66 delete = { text = '_' },
67 topdelete = { text = '‾' },
68 changedelete = { text = '~' },
70 on_attach = function(bufnr)
71 vim.keymap.set('n', '[c', require('gitsigns').prev_hunk, { buffer = bufnr, desc = 'Go to Previous Hunk' })
72 vim.keymap.set('n', ']c', require('gitsigns').next_hunk, { buffer = bufnr, desc = 'Go to Next Hunk' })
73 vim.keymap.set('n', '<leader>ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' })
78 { "ellisonleao/gruvbox.nvim", priority = 1000 },
80 -- Set lualine as statusline
81 'nvim-lualine/lualine.nvim',
82 -- See `:help lualine.txt`
85 icons_enabled = false,
87 component_separators = '|',
88 section_separators = '',
94 -- Add indentation guides even on blank lines
95 'lukas-reineke/indent-blankline.nvim',
96 -- Enable `lukas-reineke/indent-blankline.nvim`
97 -- See `:help indent_blankline.txt`
100 show_trailing_blankline_indent = false,
104 -- "gc" to comment visual regions/lines
105 { 'numToStr/Comment.nvim', opts = {} },
107 -- Fuzzy Finder (files, lsp, etc)
108 { 'nvim-telescope/telescope.nvim', branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim' } },
110 -- Fuzzy Finder Algorithm which requires local dependencies to be built.
111 -- Only load if `make` is available. Make sure you have the system
112 -- requirements installed.
114 'nvim-telescope/telescope-fzf-native.nvim',
115 -- NOTE: If you are having trouble with this installation,
116 -- refer to the README for telescope-fzf-native for more instructions.
119 return vim.fn.executable 'make' == 1
124 -- Highlight, edit, and navigate code
125 'nvim-treesitter/nvim-treesitter',
127 'nvim-treesitter/nvim-treesitter-textobjects',
132 -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
133 -- These are some example plugins that I've included in the kickstart repository.
134 -- Uncomment any of the lines below to enable them.
135 require 'autoformat',
136 -- require 'kickstart.plugins.debug',
138 -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
139 -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
140 -- up-to-date with whatever is in the kickstart repo.
142 -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
144 -- An additional note is that if you only copied in the `init.lua`, you can just comment this line
145 -- to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`.
146 -- { import = 'plugins' },
149 -- [[ Setting options ]]
152 -- Set highlight on search
153 vim.o.hlsearch = false
155 -- Make line numbers default
156 vim.wo.relativenumber = true
161 vim.opt.scrolloff = 8
163 -- Sync clipboard between OS and Neovim.
164 -- Remove this option if you want your OS clipboard to remain independent.
165 -- See `:help 'clipboard'`
166 vim.o.clipboard = 'unnamedplus'
168 -- Enable break indent
169 vim.o.breakindent = true
172 vim.o.undofile = true
174 -- Case insensitive searching UNLESS /C or capital in search
175 vim.o.ignorecase = true
176 vim.o.smartcase = true
178 -- Keep signcolumn on by default
179 vim.wo.signcolumn = 'yes'
181 -- Decrease update time
182 vim.o.updatetime = 250
184 vim.o.timeoutlen = 300
186 -- Set completeopt to have a better completion experience
187 vim.o.completeopt = 'menuone,noselect'
189 -- NOTE: You should make sure your terminal supports this
190 vim.o.termguicolors = true
192 vim.o.background = "light" -- or "light" for light mode
193 vim.cmd([[colorscheme gruvbox]])
195 -- [[ Basic Keymaps ]]
197 -- Keymaps for better default experience
198 -- See `:help vim.keymap.set()`
199 vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
201 -- Remap for dealing with word wrap
202 vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
203 vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
205 -- [[ Highlight on yank ]]
206 -- See `:help vim.highlight.on_yank()`
207 local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
208 vim.api.nvim_create_autocmd('TextYankPost', {
209 callback = function()
210 vim.highlight.on_yank()
212 group = highlight_group,
216 -- [[ Configure Telescope ]]
217 -- See `:help telescope` and `:help telescope.setup()`
218 require('telescope').setup {
229 -- Enable telescope fzf native, if installed
230 pcall(require('telescope').load_extension, 'fzf')
232 -- See `:help telescope.builtin`
233 vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
234 vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
235 vim.keymap.set('n', '<leader>/', function()
236 -- You can pass additional configuration to telescope to change theme, layout, etc.
237 require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
241 end, { desc = '[/] Fuzzily search in current buffer' })
243 vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
244 vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
245 vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
246 vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
247 vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
248 vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
250 vim.keymap.set('i', 'kj', '<Esc>')
251 vim.keymap.set("n", "<tab>", "<cmd>bn<CR>")
252 vim.keymap.set("n", "<S-tab>", "<cmd>bp<CR>")
256 autocmd BufReadPost *
257 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
258 \ | exe "normal! g`\""
263 -- [[ Configure Treesitter ]]
264 -- See `:help nvim-treesitter`
265 require('nvim-treesitter.configs').setup {
266 -- Add languages to be installed here that you want installed for treesitter
267 ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim', 'html',
268 'c_sharp', 'perl', 'python' },
270 -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
271 auto_install = false,
273 highlight = { enable = true },
274 indent = { enable = true, disable = { 'python' } },
275 incremental_selection = {
278 init_selection = '<c-space>',
279 node_incremental = '<c-space>',
280 scope_incremental = '<c-s>',
281 node_decremental = '<M-space>',
287 lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
289 -- You can use the capture groups defined in textobjects.scm
290 ['aa'] = '@parameter.outer',
291 ['ia'] = '@parameter.inner',
292 ['af'] = '@function.outer',
293 ['if'] = '@function.inner',
294 ['ac'] = '@class.outer',
295 ['ic'] = '@class.inner',
300 set_jumps = true, -- whether to set jumps in the jumplist
302 [']m'] = '@function.outer',
303 [']]'] = '@class.outer',
306 [']M'] = '@function.outer',
307 [']['] = '@class.outer',
309 goto_previous_start = {
310 ['[m'] = '@function.outer',
311 ['[['] = '@class.outer',
313 goto_previous_end = {
314 ['[M'] = '@function.outer',
315 ['[]'] = '@class.outer',
321 ['<leader>A'] = '@parameter.inner',
324 ['<leader>a'] = '@parameter.inner',
330 -- Diagnostic keymaps
331 vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
332 vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
333 vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
334 vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
337 -- This function gets run when an LSP connects to a particular buffer.
338 local on_attach = function(_, bufnr)
339 -- NOTE: Remember that lua is a real programming language, and as such it is possible
340 -- to define small helper and utility functions so you don't have to repeat yourself
342 -- for LSP related items. It sets the mode, buffer and description for us each time.
343 local nmap = function(keys, func, desc)
345 desc = 'LSP: ' .. desc
348 vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
351 nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
352 nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
354 nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
355 nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
356 nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
357 nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
358 nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
359 nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
361 -- See `:help K` for why this keymap
362 nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
363 nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
365 -- Lesser used LSP functionality
366 nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
367 nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
368 nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
369 nmap('<leader>wl', function()
370 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
371 end, '[W]orkspace [L]ist Folders')
373 -- Create a command `:Format` local to the LSP buffer
374 vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
376 end, { desc = 'Format current buffer with LSP' })
379 -- Enable the following language servers
380 -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
382 -- Add any additional override configuration in the following tables. They will be passed to
383 -- the `settings` field of the server config. You must look up that documentation yourself.
388 -- rust_analyzer = {},
392 workspace = { checkThirdParty = false },
393 telemetry = { enable = false },
398 -- Setup neovim lua configuration
399 require('neodev').setup()
401 -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
402 local capabilities = vim.lsp.protocol.make_client_capabilities()
403 capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
405 -- Ensure the servers above are installed
406 local mason_lspconfig = require 'mason-lspconfig'
408 mason_lspconfig.setup {
409 ensure_installed = vim.tbl_keys(servers),
412 mason_lspconfig.setup_handlers {
413 function(server_name)
414 require('lspconfig')[server_name].setup {
415 capabilities = capabilities,
416 on_attach = on_attach,
417 settings = servers[server_name],
423 local cmp = require 'cmp'
424 local luasnip = require 'luasnip'
425 require('luasnip.loaders.from_vscode').lazy_load()
426 luasnip.config.setup {}
430 expand = function(args)
431 luasnip.lsp_expand(args.body)
434 mapping = cmp.mapping.preset.insert {
435 ['<C-n>'] = cmp.mapping.select_next_item(),
436 ['<C-p>'] = cmp.mapping.select_prev_item(),
437 ['<C-d>'] = cmp.mapping.scroll_docs(-4),
438 ['<C-f>'] = cmp.mapping.scroll_docs(4),
439 ['<C-Space>'] = cmp.mapping.complete {},
440 ['<CR>'] = cmp.mapping.confirm {
441 behavior = cmp.ConfirmBehavior.Replace,
444 ['<Tab>'] = cmp.mapping(function(fallback)
445 if cmp.visible() then
446 cmp.select_next_item()
447 elseif luasnip.expand_or_locally_jumpable() then
448 luasnip.expand_or_jump()
453 ['<S-Tab>'] = cmp.mapping(function(fallback)
454 if cmp.visible() then
455 cmp.select_prev_item()
456 elseif luasnip.locally_jumpable(-1) then
464 { name = 'nvim_lsp' },
465 { name = 'luasnip' },
469 -- The line beneath this is called `modeline`. See `:help modeline`
470 -- vim: ts=2 sts=2 sw=2 et