2023-02-17 21:31:57 +00:00
|
|
|
--[[
|
|
|
|
|
|
|
|
=====================================================================
|
|
|
|
==================== READ THIS BEFORE CONTINUING ====================
|
|
|
|
=====================================================================
|
|
|
|
|
|
|
|
Kickstart.nvim is *not* a distribution.
|
|
|
|
|
|
|
|
Kickstart.nvim is a template for your own configuration.
|
2023-05-22 18:29:42 +00:00
|
|
|
The goal is that you can read every line of code, top-to-bottom, understand
|
|
|
|
what your configuration is doing, and modify it to suit your needs.
|
2023-02-17 21:31:57 +00:00
|
|
|
|
|
|
|
Once you've done that, you should start exploring, configuring and tinkering to
|
|
|
|
explore Neovim!
|
|
|
|
|
|
|
|
If you don't know anything about Lua, I recommend taking some time to read through
|
|
|
|
a guide. One possible example:
|
|
|
|
- https://learnxinyminutes.com/docs/lua/
|
|
|
|
|
2023-08-10 19:00:15 +00:00
|
|
|
|
2023-02-17 21:31:57 +00:00
|
|
|
And then you can explore or search through `:help lua-guide`
|
2023-08-10 19:00:15 +00:00
|
|
|
- https://neovim.io/doc/user/lua-guide.html
|
2023-02-17 21:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
Kickstart Guide:
|
|
|
|
|
|
|
|
I have left several `:help X` comments throughout the init.lua
|
|
|
|
You should run that command and read that help section for more information.
|
|
|
|
|
|
|
|
In addition, I have some `NOTE:` items throughout the file.
|
|
|
|
These are for you, the reader to help understand what is happening. Feel free to delete
|
|
|
|
them once you know what you're doing, but they should serve as a guide for when you
|
|
|
|
are first encountering a few different constructs in your nvim config.
|
|
|
|
|
|
|
|
I hope you enjoy your Neovim journey,
|
|
|
|
- TJ
|
|
|
|
|
|
|
|
P.S. You can delete this when you're done too. It's your config now :)
|
|
|
|
--]]
|
2023-10-22 09:44:31 +00:00
|
|
|
|
2023-02-17 21:31:57 +00:00
|
|
|
-- Set <space> as the leader key
|
|
|
|
-- See `:help mapleader`
|
|
|
|
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
|
|
|
|
vim.g.mapleader = ' '
|
|
|
|
vim.g.maplocalleader = ' '
|
|
|
|
|
2023-10-22 09:44:31 +00:00
|
|
|
-- Install lazy plugin manager
|
|
|
|
require('lazy-bootstrap')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-10-22 09:50:38 +00:00
|
|
|
-- Setup lazy plugin manager - configure plugins
|
|
|
|
require('lazy-plugins')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-10-22 10:13:07 +00:00
|
|
|
-- Set options
|
|
|
|
require('options')
|
2023-02-17 21:31:57 +00:00
|
|
|
|
2023-10-22 10:16:17 +00:00
|
|
|
-- Configure keymaps
|
|
|
|
require('keymaps')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-10-22 10:24:25 +00:00
|
|
|
-- Configure Telescope (fuzzy finder)
|
|
|
|
require('telescope-setup')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-10-22 10:27:28 +00:00
|
|
|
-- Configure Treesitter (syntax parser for highlighting)
|
|
|
|
require('treesitter-setup')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-05-22 06:46:09 +00:00
|
|
|
-- [[ Configure LSP ]]
|
2022-06-24 03:35:53 +00:00
|
|
|
-- This function gets run when an LSP connects to a particular buffer.
|
|
|
|
local on_attach = function(_, bufnr)
|
|
|
|
-- NOTE: Remember that lua is a real programming language, and as such it is possible
|
|
|
|
-- to define small helper and utility functions so you don't have to repeat yourself
|
|
|
|
-- many times.
|
|
|
|
--
|
|
|
|
-- In this case, we create a function that lets us more easily define mappings specific
|
|
|
|
-- for LSP related items. It sets the mode, buffer and description for us each time.
|
|
|
|
local nmap = function(keys, func, desc)
|
|
|
|
if desc then
|
|
|
|
desc = 'LSP: ' .. desc
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
|
|
|
|
end
|
|
|
|
|
|
|
|
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
|
2022-06-24 16:19:15 +00:00
|
|
|
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
|
2022-06-24 03:35:53 +00:00
|
|
|
|
2023-10-13 07:21:10 +00:00
|
|
|
nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
|
2022-11-19 02:04:04 +00:00
|
|
|
nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
|
2023-08-21 21:19:13 +00:00
|
|
|
nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
|
2023-10-13 07:21:10 +00:00
|
|
|
nmap('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
|
2022-06-24 03:35:53 +00:00
|
|
|
nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
|
|
|
|
nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
|
|
|
|
|
|
|
|
-- See `:help K` for why this keymap
|
|
|
|
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
|
|
|
|
nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
|
|
|
|
|
|
|
|
-- Lesser used LSP functionality
|
|
|
|
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
|
|
|
|
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
|
|
|
|
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
|
|
|
|
nmap('<leader>wl', function()
|
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end, '[W]orkspace [L]ist Folders')
|
|
|
|
|
|
|
|
-- Create a command `:Format` local to the LSP buffer
|
2022-08-24 08:17:50 +00:00
|
|
|
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
|
2022-12-21 03:12:39 +00:00
|
|
|
vim.lsp.buf.format()
|
2022-08-24 08:17:50 +00:00
|
|
|
end, { desc = 'Format current buffer with LSP' })
|
2022-06-24 03:35:53 +00:00
|
|
|
end
|
|
|
|
|
2023-09-24 08:24:33 +00:00
|
|
|
-- document existing key chains
|
2023-10-06 23:25:57 +00:00
|
|
|
require('which-key').register {
|
2023-09-24 08:24:33 +00:00
|
|
|
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
|
|
|
|
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
|
|
|
|
['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
|
|
|
|
['<leader>h'] = { name = 'More git', _ = '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' },
|
2023-10-06 23:25:57 +00:00
|
|
|
}
|
2023-09-24 08:24:33 +00:00
|
|
|
|
2023-10-07 23:14:26 +00:00
|
|
|
-- mason-lspconfig requires that these setup functions are called in this order
|
|
|
|
-- before setting up the servers.
|
|
|
|
require('mason').setup()
|
|
|
|
require('mason-lspconfig').setup()
|
|
|
|
|
2022-06-24 03:35:53 +00:00
|
|
|
-- Enable the following language servers
|
2022-12-21 03:12:39 +00:00
|
|
|
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
|
|
|
|
--
|
|
|
|
-- Add any additional override configuration in the following tables. They will be passed to
|
|
|
|
-- the `settings` field of the server config. You must look up that documentation yourself.
|
2023-07-24 18:41:14 +00:00
|
|
|
--
|
|
|
|
-- If you want to override the default filetypes that your language server will attach to you can
|
|
|
|
-- define the property 'filetypes' to the map in question.
|
2022-12-21 03:12:39 +00:00
|
|
|
local servers = {
|
|
|
|
-- clangd = {},
|
|
|
|
-- gopls = {},
|
|
|
|
-- pyright = {},
|
|
|
|
-- rust_analyzer = {},
|
|
|
|
-- tsserver = {},
|
2023-07-24 18:41:14 +00:00
|
|
|
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
|
2022-12-21 03:12:39 +00:00
|
|
|
|
2023-02-17 21:31:57 +00:00
|
|
|
lua_ls = {
|
2022-12-21 03:12:39 +00:00
|
|
|
Lua = {
|
|
|
|
workspace = { checkThirdParty = false },
|
|
|
|
telemetry = { enable = false },
|
|
|
|
},
|
|
|
|
},
|
2022-06-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 03:12:39 +00:00
|
|
|
-- Setup neovim lua configuration
|
|
|
|
require('neodev').setup()
|
2023-02-17 21:31:57 +00:00
|
|
|
|
2022-12-21 03:12:39 +00:00
|
|
|
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
|
2022-11-19 02:04:04 +00:00
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
|
|
|
|
|
2022-12-21 03:12:39 +00:00
|
|
|
-- Ensure the servers above are installed
|
|
|
|
local mason_lspconfig = require 'mason-lspconfig'
|
2022-11-19 02:04:04 +00:00
|
|
|
|
2022-12-21 03:12:39 +00:00
|
|
|
mason_lspconfig.setup {
|
|
|
|
ensure_installed = vim.tbl_keys(servers),
|
|
|
|
}
|
|
|
|
|
|
|
|
mason_lspconfig.setup_handlers {
|
|
|
|
function(server_name)
|
|
|
|
require('lspconfig')[server_name].setup {
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = on_attach,
|
|
|
|
settings = servers[server_name],
|
2023-07-25 15:06:04 +00:00
|
|
|
filetypes = (servers[server_name] or {}).filetypes,
|
2022-12-21 03:12:39 +00:00
|
|
|
}
|
2023-10-06 23:25:57 +00:00
|
|
|
end,
|
2022-06-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 06:46:09 +00:00
|
|
|
-- [[ Configure nvim-cmp ]]
|
|
|
|
-- See `:help cmp`
|
2022-06-24 03:35:53 +00:00
|
|
|
local cmp = require 'cmp'
|
|
|
|
local luasnip = require 'luasnip'
|
2023-05-16 19:38:56 +00:00
|
|
|
require('luasnip.loaders.from_vscode').lazy_load()
|
2023-02-17 21:31:57 +00:00
|
|
|
luasnip.config.setup {}
|
|
|
|
|
2022-06-24 03:35:53 +00:00
|
|
|
cmp.setup {
|
|
|
|
snippet = {
|
|
|
|
expand = function(args)
|
|
|
|
luasnip.lsp_expand(args.body)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
mapping = cmp.mapping.preset.insert {
|
2023-04-27 07:33:10 +00:00
|
|
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
|
|
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
2022-06-24 03:35:53 +00:00
|
|
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
|
|
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
2023-02-17 21:31:57 +00:00
|
|
|
['<C-Space>'] = cmp.mapping.complete {},
|
2022-06-24 03:35:53 +00:00
|
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
select = true,
|
|
|
|
},
|
|
|
|
['<Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
2023-05-07 23:28:13 +00:00
|
|
|
elseif luasnip.expand_or_locally_jumpable() then
|
2022-06-24 03:35:53 +00:00
|
|
|
luasnip.expand_or_jump()
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
2023-05-07 23:38:44 +00:00
|
|
|
elseif luasnip.locally_jumpable(-1) then
|
2022-06-24 03:35:53 +00:00
|
|
|
luasnip.jump(-1)
|
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end, { 'i', 's' }),
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = 'nvim_lsp' },
|
|
|
|
{ name = 'luasnip' },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
-- The line beneath this is called `modeline`. See `:help modeline`
|
|
|
|
-- vim: ts=2 sts=2 sw=2 et
|