From e9f8139fcf32112cf0b8bd7b4b4d991572247034 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 21 Feb 2024 15:56:24 -0500 Subject: [PATCH] wip: more work from twitch --- init.lua | 353 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 219 insertions(+), 134 deletions(-) diff --git a/init.lua b/init.lua index 1ad34ee..6f706be 100644 --- a/init.lua +++ b/init.lua @@ -153,10 +153,190 @@ vim.opt.rtp:prepend(lazypath) -- You can also configure plugins after the setup call, -- as they will be available in your neovim runtime. require('lazy').setup({ - -- NOTE: First, some plugins that don't require any configuration + -- NOTE: Plugins can be added by simply giving a link or 'owner/repo' link. - -- Detect tabstop and shiftwidth automatically - 'tpope/vim-sleuth', + 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically + + -- NOTE: Plugins can also be added by using a table, + -- with the first argument being the 'owner/repo' and then following + -- keys can be used to configure plugin behavior. + -- + -- For example, using: + -- opts = { ... } + -- + -- is the same as doing: + -- require("myplugin").setup { ... } + -- + -- Lazy will automatically load and run the setup for this plugin + + { -- Autoformat + 'stevearc/conform.nvim', + event = 'VeryLazy', + opts = { + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, + formatters_by_ft = { + lua = { 'stylua' }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use a sub-list to tell conform to run *until* a formatter + -- is found. + -- javascript = { { "prettierd", "prettier" } }, + }, + }, + }, + + -- NOTE: Plugins can also be configured to run lua code when they are loaded. + -- + -- This is often very useful to both group configuration, as well as handle + -- lazy loading plugins that don't need to be loaded immediately at startup. + -- + -- For example, in the following configuration, we use: + -- event = 'VeryLazy' + -- + -- which loads which-key after all the UI elements are loaded. + -- + -- Then, because we use the `config` key, the configuration only runs + -- after the plugin has been loaded: + -- config = function() ... end + + { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VeryLazy', + config = function() + require('which-key').setup() + + -- document existing key chains + require('which-key').register { + ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, + ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, + ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, + ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, + ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, + ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, + ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, + } + end, + }, + + -- NOTE: Plugins can specify dependencies. + -- + -- The dependencies are proper plugin specifications as well - anything + -- you do for a plugin at the top level, you can do for a dependency. + -- + -- Use the `dependencies` key to specify the dependencies of a particular plugin + + { -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + event = 'VeryLazy', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for install instructions + 'nvim-telescope/telescope-fzf-native.nvim', + -- NOTE: `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', + + -- NOTE: `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires special font. + -- If you already have a Nerd Font, or terminal set up with fallback fonts + -- you can enable this + -- { 'nvim-tree/nvim-web-devicons' } + }, + config = function() + -- [[ Configure Telescope ]] + -- See `:help telescope` and `:help telescope.setup()` + require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + }, + }, + }, + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, + } + + -- Enable telescope fzf native, if installed + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- Telescope is a fuzzy finder that comes with a lot of different things that + -- it can fuzzy find! It's more than just a "file finder", it can search + -- many different aspects of Neovim, your workspace, LSP, and more! + -- + -- The easiest way to use telescope, is to start by doing something like: + -- :Telescope help_tags + -- + -- After running this command, a window will open up and you're able to + -- type in the prompt window. You'll see a list of help_tags options and + -- a corresponding preview of the help. + -- + -- Two important keymaps to use while in telescope are: + -- - Insert mode: + -- - Normal mode: ? + -- + -- This opens a window that shows you all of the keymaps for the current + -- telescope picker. This is really useful to discover what Telescope can + -- do as well as how to actually do it! + + -- See `:help telescope.builtin` + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) + vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) + vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) + vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) + vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) + vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) + vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'gf', builtin.git_files, { desc = 'Search [G]it [F]iles' }) + vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + + -- Slightly advanced example of overriding default behavior and theme + vim.keymap.set('n', '/', function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = '[/] Fuzzily search in current buffer' }) + + -- Also possible to pass additional configuration options. + -- See `:help telescope.builtin.live_grep()` for information about particular pickers + vim.keymap.set('n', 's/', function() + builtin.live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, { desc = '[S]earch [/] in Open Files' }) + + -- Shortcut for searching your neovim configuration files + vim.keymap.set('n', 'sn', function() + builtin.find_files { + cwd = vim.fn.stdpath 'config', + } + end, { desc = '[S]earch [N]eovim files' }) + end, + }, { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', @@ -164,6 +344,7 @@ require('lazy').setup({ -- Automatically install LSPs to stdpath for neovim 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', + 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', @@ -173,6 +354,31 @@ require('lazy').setup({ { 'j-hui/fidget.nvim', opts = {} }, }, config = function() + -- Brief Aside: **What is LSP?** + -- + -- LSP is an acronym you've probably heard, but might not understand what it is. + -- + -- LSP stands for Language Server Protocol. It's a protocol that helps editors + -- and language tooling communicate in a standardized fashion. + -- + -- In general, you have a "server" which is some tool built to understand a particular + -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc). These Language Servers + -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone + -- processes that communicate with some "client" - in this case, Neovim! + -- + -- LSP provides Neovim with features like: + -- - Go to definition + -- - Find references + -- - Autocompletion + -- - Symbol Search + -- - and more! + -- + -- Thus, Language Servers are external tools that must be installed separately from + -- Neovim. This is where `mason` and `mason-lspconfig` both come into play. + -- + -- If you're wondering about lsp vs treesitter, you can check out the wonderfully + -- and elegantly composed help section, :help lsp-vs-treesitter + -- First, enable neodev. This is helpful for auto-configuring the Lua LSP -- to understand your Neovim environment require('neodev').setup() @@ -260,8 +466,12 @@ require('lazy').setup({ -- Ensure the servers above are installed require('mason').setup() + + -- TODO: Think about lspconfig mason + local installed = { 'stylua' } + vim.list_extend(installed, vim.tbl_keys(servers)) + require('mason-tool-installer').setup { ensure_installed = installed } require('mason-lspconfig').setup { - ensure_installed = vim.tbl_keys(servers), handlers = { function(server_name) local server = servers[server_name] or {} @@ -280,25 +490,9 @@ require('lazy').setup({ end, }, - { -- Autoformat - 'stevearc/conform.nvim', - opts = { - format_on_save = { - timeout_ms = 500, - lsp_fallback = true, - }, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform will run multiple formatters sequentially - -- python = { "isort", "black" }, - -- Use a sub-list to run only the first available formatter - -- javascript = { { "prettierd", "prettier" } }, - }, - }, - }, - { -- Autocompletion 'hrsh7th/nvim-cmp', + event = 'InsertEnter', dependencies = { -- Snippet Engine & its associated nvim-cmp source { @@ -379,26 +573,6 @@ require('lazy').setup({ end, }, - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VeryLazy', - config = function() - require('which-key').setup() - - -- document existing key chains - require('which-key').register { - ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, - ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, - ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, - ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, - ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, - ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, - ['t'] = { name = '[T]oggle', _ = 'which_key_ignore' }, - ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, - } - end, - }, - { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', opts = { @@ -414,6 +588,10 @@ require('lazy').setup({ }, { -- You can easily change to a different colorscheme. + -- Change the name of the colorscheme plugin below, and then + -- change the command in the config to whatever the name of that colorscheme is + -- + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme` 'folke/tokyonight.nvim', lazy = false, -- make sure we load this during startup if it is your main colorscheme priority = 1000, -- make sure to load this before all the other start plugins @@ -446,102 +624,9 @@ require('lazy').setup({ end, }, - -- { -- Set lualine as statusline - -- 'nvim-lualine/lualine.nvim', - -- -- See `:help lualine.txt` - -- opts = { - -- options = { - -- icons_enabled = false, - -- theme = 'auto', - -- component_separators = '|', - -- section_separators = '', - -- }, - -- }, - -- }, - -- "gc" to comment visual regions/lines { 'numToStr/Comment.nvim', opts = {} }, - { -- Fuzzy Finder (files, lsp, etc) - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - -- Fuzzy Finder Algorithm which requires local dependencies to be built. - -- Only load if `make` is available. Make sure you have the system - -- requirements installed. - { - 'nvim-telescope/telescope-fzf-native.nvim', - -- NOTE: If you are having trouble with this installation, - -- refer to the README for telescope-fzf-native for more instructions. - build = 'make', - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - { 'nvim-telescope/telescope-ui-select.nvim' }, - -- Useful for getting pretty icons, but requires special font. - -- If you already have a Nerd Font, or terminal set up with fallback fonts - -- you can enable this - -- { 'nvim-tree/nvim-web-devicons' } - }, - config = function() - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - defaults = { - mappings = { - i = { - [''] = false, - [''] = false, - }, - }, - }, - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable telescope fzf native, if installed - pcall(require('telescope').load_extension, 'fzf') - pcall(require('telescope').load_extension, 'ui-select') - - -- See `:help telescope.builtin` - local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', 'gf', builtin.git_files, { desc = 'Search [G]it [F]iles' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to telescope to change theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) - - -- Also possible to pass additional configuration options. - -- See `:help telescope.builtin.live_grep()` for information about particular pickers - vim.keymap.set('n', 's/', function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, { desc = '[S]earch [/] in Open Files' }) - end, - }, - { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate',