This commit is contained in:
TJ DeVries 2024-02-23 12:51:28 -05:00
parent 532dbef6b4
commit 65cbba91ab

132
init.lua
View file

@ -20,6 +20,8 @@
===================================================================== =====================================================================
===================================================================== =====================================================================
What is Kickstart?
Kickstart.nvim is *not* a distribution. Kickstart.nvim is *not* a distribution.
Kickstart.nvim is a starting point for your own configuration. Kickstart.nvim is a starting point for your own configuration.
@ -41,7 +43,8 @@ Kickstart.nvim is a starting point for your own configuration.
Kickstart Guide: Kickstart Guide:
The very first thing you should do, is run the command `:Tutor` inside Neovim. TODO: The very first thing you should do is to run the command `:Tutor` in Neovim.
If you don't know what this means, type the following: If you don't know what this means, type the following:
- <escape key> - <escape key>
- : - :
@ -60,11 +63,12 @@ Kickstart Guide:
This should be the first place you go to look when you're stuck or confused This should be the first place you go to look when you're stuck or confused
with something. It's one of my favorite neovim features. with something. It's one of my favorite neovim features.
MOST IMPORTANTLY, we provide a keymap "<leader>sh" to [s]earch the [h]elp documentation, MOST IMPORTANTLY, we provide a keymap "<space>sh" to [s]earch the [h]elp documentation,
which is very useful when you're not sure exactly what you're looking for. which is very useful when you're not sure exactly what you're looking for.
I have left several `:help X` comments throughout the init.lua I have left several `:help X` comments throughout the init.lua
You should run that command and read that help section for more information. These are hints about where to find more information about the relevant settings,
plugins or neovim features used in kickstart.
NOTE: Look for lines like this NOTE: Look for lines like this
@ -80,7 +84,7 @@ P.S. You can delete this when you're done too. It's your config now! :)
-- Set <space> as the leader key -- Set <space> as the leader key
-- See `:help mapleader` -- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = ' ' vim.g.mapleader = ' '
vim.g.maplocalleader = ' ' vim.g.maplocalleader = ' '
@ -95,9 +99,12 @@ vim.opt.number = true
-- Experiment for yourself to see if you like it! -- Experiment for yourself to see if you like it!
-- vim.opt.relativenumber = true -- vim.opt.relativenumber = true
-- Enable mouse mode -- Enable mouse mode, can be useful for resizing splits for example!
vim.opt.mouse = 'a' vim.opt.mouse = 'a'
-- Don't show the mode, since it's already in status line
vim.opt.showmode = false
-- Sync clipboard between OS and Neovim. -- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent. -- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'` -- See `:help 'clipboard'`
@ -130,40 +137,56 @@ vim.opt.splitbelow = true
vim.opt.list = true vim.opt.list = true
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '' } vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '' }
-- Preview substitutions live -- Preview substitutions live, as you type!
vim.opt.inccommand = 'split' vim.opt.inccommand = 'split'
-- Show which line your cursor is on
vim.opt.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor.
vim.opt.scrolloff = 10
-- [[ Basic Keymaps ]] -- [[ Basic Keymaps ]]
-- Set highlight on search
vim.opt.hlsearch = true
-- Clear highlighting on pressing Escape
vim.keymap.set('n', '<Esc>', '<esc>:nohlsearch<CR>', { silent = true })
-- Keymaps for better default experience
-- See `:help vim.keymap.set()` -- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
-- Remap for dealing with word wrap -- Set highlight on search, but clear on pressing <Esc> in normal mode
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) vim.opt.hlsearch = true
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Diagnostic keymaps -- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <c-\><c-n>, which -- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience. -- is not what someone will guess without a bit more experience.
vim.keymap.set('t', '<esc><esc>', '<c-\\><c-n>', { desc = 'Escape Escape exits terminal mode' }) --
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- [[ Highlight on yank ]] -- TIP: Disable arrow keys in normal mode
-- vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
-- vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
-- vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
-- vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
--
-- 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' })
-- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()` -- See `:help vim.highlight.on_yank()`
vim.api.nvim_create_autocmd('TextYankPost', { vim.api.nvim_create_autocmd('TextYankPost', {
group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }), group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function() callback = function()
vim.highlight.on_yank() vim.highlight.on_yank()
end, end,
@ -175,7 +198,7 @@ local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git' local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
end end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
-- [[ Configure and install plugins ]] -- [[ Configure and install plugins ]]
@ -183,7 +206,7 @@ vim.opt.rtp:prepend(lazypath)
-- To check the current status of your plugins, run -- To check the current status of your plugins, run
-- :Lazy -- :Lazy
-- --
-- You can press `?` in this menu for help. -- You can press `?` in this menu for help. Use `:q` to close the window
-- --
-- To update plugins, you can run -- To update plugins, you can run
-- :Lazy update -- :Lazy update
@ -207,12 +230,14 @@ require('lazy').setup({
{ 'numToStr/Comment.nvim', opts = {} }, { 'numToStr/Comment.nvim', opts = {} },
-- Here is a more advanced example where we pass configuration -- Here is a more advanced example where we pass configuration
-- options to `conform.nvim`. -- options to `conform.nvim`. This is equivalent to:
-- require('conform').setup({ ... })
-- --
-- See `:help conform` to understand what the configuration keys do -- See `:help conform` to understand what the configuration keys do
{ -- Autoformat { -- Autoformat
'stevearc/conform.nvim', 'stevearc/conform.nvim',
opts = { opts = {
notify_on_error = false,
format_on_save = { format_on_save = {
timeout_ms = 500, timeout_ms = 500,
lsp_fallback = true, lsp_fallback = true,
@ -250,15 +275,12 @@ require('lazy').setup({
config = function() -- This is the function that runs, AFTER loading config = function() -- This is the function that runs, AFTER loading
require('which-key').setup() require('which-key').setup()
-- document existing key chains -- Document existing key chains
require('which-key').register { require('which-key').register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' }, ['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, ['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>g'] = { name = '[G]it', _ = 'which_key_ignore' },
['<leader>h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' }, ['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' }, ['<leader>s'] = { name = '[S]earch', _ = 'which_key_ignore' },
['<leader>t'] = { name = '[T]oggle', _ = 'which_key_ignore' },
['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, ['<leader>w'] = { name = '[W]orkspace', _ = 'which_key_ignore' },
} }
end, end,
@ -363,7 +385,7 @@ require('lazy').setup({
end, { desc = '[/] Fuzzily search in current buffer' }) end, { desc = '[/] Fuzzily search in current buffer' })
-- Also possible to pass additional configuration options. -- Also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular pickers -- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set('n', '<leader>s/', function() vim.keymap.set('n', '<leader>s/', function()
builtin.live_grep { builtin.live_grep {
grep_open_files = true, grep_open_files = true,
@ -383,7 +405,7 @@ require('lazy').setup({
{ -- LSP Configuration & Plugins { -- LSP Configuration & Plugins
'neovim/nvim-lspconfig', 'neovim/nvim-lspconfig',
dependencies = { dependencies = {
-- Automatically install LSPs to stdpath for neovim -- Automatically install LSPs and related tools to stdpath for neovim
'williamboman/mason.nvim', 'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim', 'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim',
@ -413,17 +435,17 @@ require('lazy').setup({
-- - and more! -- - and more!
-- --
-- Thus, Language Servers are external tools that must be installed separately from -- Thus, Language Servers are external tools that must be installed separately from
-- Neovim. This is where `mason` and `mason-lspconfig` both come into play. -- Neovim. This is where `mason` and related plugins come into play.
-- --
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully -- If you're wondering about lsp vs treesitter, you can check out the wonderfully
-- and elegantly composed help section, :help lsp-vs-treesitter -- and elegantly composed help section, :help lsp-vs-treesitter
-- This function gets run when an LSP connects to a particular buffer. -- This function gets run when an LSP attaches to a particular buffer.
-- That is to say, every time a new file is opened that is associated with -- That is to say, every time a new file is opened that is associated with
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
-- function will be executed to configure the current buffer -- function will be executed to configure the current buffer
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('custom-lsp-attach', { clear = true }), group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event) callback = function(event)
-- NOTE: Remember that lua is a real programming language, and as such it is possible -- 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 -- to define small helper and utility functions so you don't have to repeat yourself
@ -435,22 +457,33 @@ require('lazy').setup({
vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) vim.keymap.set('n', keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end end
-- Important LSP Navigation keybinds
--
-- Jump to the definition of the word under your cursor. -- Jump to the definition of the word under your cursor.
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-T>. -- To jump back, press <C-T>.
map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
-- Find references for the word under your cursor.
map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
-- Jump to the type of the word under your cursor.
-- Useful when you're not sure what type a variable is and you want to see
-- the definition of it's *type*, not where it was *defined*.
map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') map('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
-- Fuzzy find all the symbols in your current workspace
-- Similar to document symbols, except searches over your whole project.
map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
-- WARN: This is not Goto Definition, this is Goto Declaration.
-- For example, in C this would take you to the header
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
-- Rename the variable under your cursor -- Rename the variable under your cursor
-- Most Language Servers support renaming across files, etc.
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame') map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
-- Execute a code action, usually your cursor needs to be on top of an error -- Execute a code action, usually your cursor needs to be on top of an error
@ -459,19 +492,25 @@ require('lazy').setup({
vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } } vim.lsp.buf.code_action { context = { only = { 'quickfix', 'refactor', 'source' } } }
end, '[C]ode [A]ction') end, '[C]ode [A]ction')
-- Opens a popup that displays documentation about the word under your cursor
-- See `:help K` for why this keymap -- See `:help K` for why this keymap
map('K', vim.lsp.buf.hover, 'Hover Documentation') map('K', vim.lsp.buf.hover, 'Hover Documentation')
-- Show the signature of the function you're currently completing. -- Show the signature of the function you're currently completing.
map('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation') map('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- WARN: This is not Goto Definition, this is Goto Declaration.
-- For example, in C this would take you to the header
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
end, end,
}) })
-- LSP servers and clients are able to communicate to each other what features they support. -- LSP servers and clients are able to communicate to each other what features they support.
-- By default, Neovim doesn't support everything that is in the LSP Specification. -- By default, Neovim doesn't support everything that is in the LSP Specification.
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
-- So, we create new capabilties with nvim cmp, and then broadcast that to the servers. -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers.
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())
-- Enable the following language servers -- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
@ -506,6 +545,8 @@ require('lazy').setup({
runtime = { version = 'LuaJIT' }, runtime = { version = 'LuaJIT' },
workspace = { workspace = {
checkThirdParty = false, checkThirdParty = false,
-- Tells lua_ls where to find all the Lua files that you have loaded
-- for your neovim configuration.
library = { library = {
'${3rd}/luv/library', '${3rd}/luv/library',
unpack(vim.api.nvim_get_runtime_file('', true)), unpack(vim.api.nvim_get_runtime_file('', true)),
@ -513,7 +554,6 @@ require('lazy').setup({
-- If lua_ls is really slow on your computer, you can try this instead: -- If lua_ls is really slow on your computer, you can try this instead:
-- library = { vim.env.VIMRUNTIME }, -- library = { vim.env.VIMRUNTIME },
}, },
telemetry = { enable = false },
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
-- diagnostics = { disable = { 'missing-fields' } }, -- diagnostics = { disable = { 'missing-fields' } },
}, },
@ -731,7 +771,7 @@ require('lazy').setup({
-- init.lua. If you want these files, they are in the repository, so you can just download them and -- init.lua. If you want these files, they are in the repository, so you can just download them and
-- put them in the right spots if you want. -- put them in the right spots if you want.
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "" for kickstart
-- These are some example plugins that I've included in the kickstart repository. -- These are some example plugins that I've included in the kickstart repository.
-- Uncomment any of the lines below to enable them. -- Uncomment any of the lines below to enable them.
-- require 'kickstart.plugins.debug', -- require 'kickstart.plugins.debug',