diff --git a/init.lua b/init.lua index 10bd09f5..7fd9c54f 100644 --- a/init.lua +++ b/init.lua @@ -1,199 +1,191 @@ --- Install packer -local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' -local is_bootstrap = false -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - is_bootstrap = true - vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path } - vim.cmd [[packadd packer.nvim]] +--[[ + +===================================================================== +==================== READ THIS BEFORE CONTINUING ==================== +===================================================================== + +Kickstart.nvim is *not* a distribution. + +Kickstart.nvim is a template for your own configuration. + The goal is that you can read every line of code, top-to-bottom, and understand + what your configuration is doing. + + 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/ + + And then you can explore or search through `:help lua-guide` + + +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 :) +--]] + +-- Set 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 = ' ' + +-- Install package manager +-- https://github.com/folke/lazy.nvim +-- `:help lazy.nvim.txt` for more info +local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system { + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', -- latest stable release + lazypath, + } end +vim.opt.rtp:prepend(lazypath) -require('packer').startup(function(use) - -- Package manager - use 'wbthomason/packer.nvim' +-- NOTE: Here is where you install your plugins. +-- You can configure plugins using the `config` key. +-- +-- 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 - use { -- LSP Configuration & Plugins + -- Git related plugins + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + + -- Detect tabstop and shiftwidth automatically + 'tpope/vim-sleuth', + + -- NOTE: This is where your plugins related to LSP can be installed. + -- The configuration is done below. Search for lspconfig to find it below. + { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', - requires = { + dependencies = { -- Automatically install LSPs to stdpath for neovim - 'williamboman/mason.nvim', + { 'williamboman/mason.nvim', config = true }, 'williamboman/mason-lspconfig.nvim', -- Useful status updates for LSP - 'j-hui/fidget.nvim', + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, - -- Additional lua configuration, makes nvim stuff amazing + -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', }, - } + }, - use { -- Autocompletion + { -- Autocompletion 'hrsh7th/nvim-cmp', - requires = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, - } + dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }, + }, - use { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - run = function() - pcall(require('nvim-treesitter.install').update { with_sync = true }) + -- Useful plugin to show you pending keybinds. + { 'folke/which-key.nvim', opts = {} }, + { -- Adds git releated signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + -- See `:help gitsigns.txt` + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + }, + }, + + { -- Theme inspired by Atom + 'navarasu/onedark.nvim', + priority = 1000, + config = function() + vim.cmd.colorscheme 'onedark' end, - } + }, - use { -- Additional text objects via treesitter - 'nvim-treesitter/nvim-treesitter-textobjects', - after = 'nvim-treesitter', - } + { -- Set lualine as statusline + 'nvim-lualine/lualine.nvim', + -- See `:help lualine.txt` + opts = { + options = { + icons_enabled = false, + theme = 'onedark', + component_separators = '|', + section_separators = '', + }, + }, + }, - -- Git related plugins - use 'tpope/vim-fugitive' - use 'tpope/vim-rhubarb' - use 'lewis6991/gitsigns.nvim' + { -- Add indentation guides even on blank lines + 'lukas-reineke/indent-blankline.nvim', + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help indent_blankline.txt` + opts = { + char = '┊', + show_trailing_blankline_indent = false, + }, + }, - use 'navarasu/onedark.nvim' -- Theme inspired by Atom - use 'nvim-lualine/lualine.nvim' -- Fancier statusline - use 'lukas-reineke/indent-blankline.nvim' -- Add indentation guides even on blank lines - use 'numToStr/Comment.nvim' -- "gc" to comment visual regions/lines - use 'tpope/vim-sleuth' -- Detect tabstop and shiftwidth automatically + -- "gc" to comment visual regions/lines + { 'numToStr/Comment.nvim', opts = {} }, -- Fuzzy Finder (files, lsp, etc) - use { 'nvim-telescope/telescope.nvim', branch = '0.1.x', requires = { 'nvim-lua/plenary.nvim' } } + { 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } }, - -- Fuzzy Finder Algorithm which requires local dependencies to be built. Only load if `make` is available - use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 } + -- 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, + }, - - -- User Defined - - -- Leap to help quickly navigate + { -- Highlight, edit, and navigate code + 'nvim-treesitter/nvim-treesitter', + dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', + }, + build = ":TSUpdate", + }, - use 'ggandor/leap.nvim' + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart + -- These are some example plugins that I've included in the kickstart repository. + -- Uncomment any of the lines below to enable them. + -- require 'kickstart.plugins.autoformat', + -- require 'kickstart.plugins.debug', - - -- Adds ability to highlight row and/or column containing cursor - use { - 'tummetott/reticle.nvim', - config = function() - require('reticle').setup { - - -- add options here or leave empty - } - end -} - - -- Shows what actions can be performed by pressing keys - use { - "folke/which-key.nvim", - config = function() - vim.o.timeout = true - vim.o.timeoutlen = 300 - require("which-key").setup { - { - plugins = { - marks = true, -- shows a list of your marks on ' and ` - registers = true, -- shows your registers on " in NORMAL or in INSERT mode - spelling = { - enabled = false, -- enabling this will show WhichKey when pressing z= to select spelling suggestions - suggestions = 20, -- how many suggestions should be shown in the list? - }, - -- the presets plugin, adds help for a bunch of default keybindings in Neovim - -- No actual key bindings are created - presets = { - operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion - motions = true, -- adds help for motions - text_objects = true, -- help for text objects triggered after entering an operator - windows = true, -- default bindings on - nav = true, -- misc bindings to work with windows - z = true, -- bindings for folds, spelling and others prefixed with z - g = true, -- bindings for prefixed with g - }, - }, - -- add operators that will trigger motion and text object completion - -- to enable all native operators, set the preset / operators plugin above - operators = { gc = "Comments" }, - key_labels = { - -- override the label used to display some keys. It doesn't effect WK in any other way. - -- For example: - -- [""] = "SPC", - -- [""] = "RET", - -- [""] = "TAB", - }, - icons = { - breadcrumb = "»", -- symbol used in the command line area that shows your active key combo - separator = "➜", -- symbol used between a key and it's label - group = "+", -- symbol prepended to a group - }, - popup_mappings = { - scroll_down = '', -- binding to scroll down inside the popup - scroll_up = '', -- binding to scroll up inside the popup - }, - window = { - border = "none", -- none, single, double, shadow - position = "bottom", -- bottom, top - margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] - padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] - winblend = 0 - }, - layout = { - height = { min = 4, max = 25 }, -- min and max height of the columns - width = { min = 20, max = 50 }, -- min and max width of the columns - spacing = 3, -- spacing between columns - align = "left", -- align columns left, center or right - }, - ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label - hidden = { "", "", "", "", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate - show_help = true, -- show help message on the command line when the popup is visible - show_keys = true, -- show the currently pressed key and its label as a message in the command line - triggers = "auto", -- automatically setup triggers - -- triggers = {""} -- or specify a list manually - triggers_blacklist = { - -- list of mode / prefixes that should never be hooked by WhichKey - -- this is mostly relevant for key maps that start with a native binding - -- most people should not need to change this - i = { "j", "k" }, - v = { "j", "k" }, - }, - -- disable the WhichKey popup for certain buf types and file types. - -- Disabled by deafult for Telescope - disable = { - buftypes = {}, - filetypes = { "TelescopePrompt" }, - }, - } - } - end - } - - - -- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua - local has_plugins, plugins = pcall(require, 'custom.plugins') - if has_plugins then - plugins(use) - end - - if is_bootstrap then - require('packer').sync() - end -end) - --- When we are bootstrapping a configuration, it doesn't --- make sense to execute the rest of the init.lua. --- --- You'll need to restart nvim, and then it will work. -if is_bootstrap then - print '==================================' - print ' Plugins are being installed' - print ' Wait until Packer completes,' - print ' then restart nvim' - print '==================================' - return -end - --- Automatically source and re-compile packer whenever you save this init.lua -local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true }) -vim.api.nvim_create_autocmd('BufWritePost', { - command = 'source | silent! LspStop | silent! LspStart | PackerCompile', - group = packer_group, - pattern = vim.fn.expand '$MYVIMRC', -}) + -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua` + -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping + -- up-to-date with whatever is in the kickstart repo. + -- + -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins + -- + -- An additional note is that if you only copied in the `init.lua`, you can just comment this line + -- to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`. + { import = 'custom.plugins' }, +}, {}) -- [[ Setting options ]] -- See `:help vim.o` @@ -207,6 +199,11 @@ vim.wo.number = true -- Enable mouse mode vim.o.mouse = 'a' +-- Sync clipboard between OS and Neovim. +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` +vim.o.clipboard = 'unnamedplus' + -- Enable break indent vim.o.breakindent = true @@ -217,23 +214,21 @@ vim.o.undofile = true vim.o.ignorecase = true vim.o.smartcase = true --- Decrease update time -vim.o.updatetime = 250 +-- Keep signcolumn on by default vim.wo.signcolumn = 'yes' --- Set colorscheme -vim.o.termguicolors = true -vim.cmd [[colorscheme onedark]] +-- Decrease update time +vim.o.updatetime = 250 +vim.o.timeout = true +vim.o.timeoutlen = 300 -- Set completeopt to have a better completion experience vim.o.completeopt = 'menuone,noselect' +-- NOTE: You should make sure your terminal supports this +vim.o.termguicolors = true + -- [[ Basic Keymaps ]] --- Set 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 = ' ' -- Keymaps for better default experience -- See `:help vim.keymap.set()` @@ -254,39 +249,6 @@ vim.api.nvim_create_autocmd('TextYankPost', { pattern = '*', }) --- Set lualine as statusline --- See `:help lualine.txt` -require('lualine').setup { - options = { - icons_enabled = false, - theme = 'onedark', - component_separators = '|', - section_separators = '', - }, -} - --- Enable Comment.nvim -require('Comment').setup() - --- Enable `lukas-reineke/indent-blankline.nvim` --- See `:help indent_blankline.txt` -require('indent_blankline').setup { - char = '┊', - show_trailing_blankline_indent = false, -} - --- Gitsigns --- See `:help gitsigns.txt` -require('gitsigns').setup { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, -} - -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` require('telescope').setup { @@ -312,8 +274,9 @@ vim.keymap.set('n', '/', function() winblend = 10, previewer = false, }) -end, { desc = '[/] Fuzzily search in current buffer]' }) +end, { desc = '[/] Fuzzily search in current buffer' }) +vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) @@ -324,7 +287,10 @@ vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { de -- See `:help nvim-treesitter` require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'help', 'vim' }, + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' }, + + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, highlight = { enable = true }, indent = { enable = true, disable = { 'python' } }, @@ -334,7 +300,7 @@ require('nvim-treesitter.configs').setup { init_selection = '', node_incremental = '', scope_incremental = '', - node_decremental = '', + node_decremental = '', }, }, textobjects = { @@ -384,10 +350,10 @@ require('nvim-treesitter.configs').setup { } -- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next) -vim.keymap.set('n', 'e', vim.diagnostic.open_float) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) -- LSP settings. -- This function gets run when an LSP connects to a particular buffer. @@ -446,7 +412,7 @@ local servers = { -- rust_analyzer = {}, -- tsserver = {}, - sumneko_lua = { + lua_ls = { Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, @@ -456,14 +422,11 @@ local servers = { -- Setup neovim lua configuration require('neodev').setup() --- + -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) --- Setup mason so it can manage external tooling -require('mason').setup() - -- Ensure the servers above are installed local mason_lspconfig = require 'mason-lspconfig' @@ -481,13 +444,12 @@ mason_lspconfig.setup_handlers { end, } --- Turn on lsp status information -require('fidget').setup() - -- nvim-cmp setup local cmp = require 'cmp' local luasnip = require 'luasnip' +luasnip.config.setup {} + cmp.setup { snippet = { expand = function(args) @@ -495,9 +457,11 @@ cmp.setup { end, }, mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), + [''] = cmp.mapping.complete {}, [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, @@ -527,35 +491,5 @@ cmp.setup { }, } --- User Defined - --- Leap setup -require('leap').add_default_mappings() - - -local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", {clear = true}) -vim.api.nvim_create_autocmd({"BufEnter", "FocusGained" ,"InsertLeave"}, { - command = "set relativenumber", - group = my_group - } -) - -vim.api.nvim_create_autocmd({"BufLeave", "FocusLost", "InsertEnter"}, { - command = "set norelativenumber", - group = my_group - } -) - - --- Use ctrl-[hjkl] to select the active split! -vim.keymap.set('n', '', {silent = true}) -vim.keymap.set('n', '', ':wincmd j', {silent = true}) -vim.keymap.set('n', '', ':wincmd h', {silent = true}) -vim.keymap.set('n', '', ':wincmd l', {silent = true}) - -vim.o.cursorline = true -vim.o.cursorcolumn = true -vim.o.smartcase = false - -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et