diff --git a/init.lua b/init.lua index 013fcc29..99be1e60 100644 --- a/init.lua +++ b/init.lua @@ -29,7 +29,7 @@ What is Kickstart? what your configuration is doing, and modify it to suit your needs. Once you've done that, you can start exploring, configuring and tinkering to - make Neovim your own! That might mean leaving Kickstart just the way it is for a while + make Neovim your own! That might mean leaving kickstart just the way it is for a while or immediately breaking it into modular pieces. It's up to you! If you don't know anything about Lua, I recommend taking some time to read through @@ -51,32 +51,32 @@ Kickstart Guide: - Tutor - - (If you already know the Neovim basics, you can skip this step.) + (If you already know how the Neovim basics, you can skip this step) Once you've completed that, you can continue working through **AND READING** the rest - of the kickstart init.lua. + of the kickstart init.lua Next, run AND READ `:help`. This will open up a help window with some basic information about reading, navigating and searching the builtin help documentation. 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 "sh" to [s]earch the [h]elp documentation, - which is very useful when you're not exactly sure of 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 These are hints about where to find more information about the relevant settings, - plugins or Neovim features used in Kickstart. + plugins or neovim features used in kickstart. NOTE: Look for lines like this - Throughout the file. These are for you, the reader, to help you understand what is happening. + 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 Neovim config. + for when you are first encountering a few different constructs in your nvim config. -If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. +If you experience any errors while trying to install kickstart, run `:checkhealth` for more info I hope you enjoy your Neovim journey, - TJ @@ -100,14 +100,14 @@ vim.g.have_nerd_font = false -- Make line numbers default vim.opt.number = true --- You can also add relative line numbers, to help with jumping. +-- You can also add relative line numbers, for help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' --- Don't show the mode, since it's already in the status line +-- Don't show the mode, since it's already in status line vim.opt.showmode = false -- Sync clipboard between OS and Neovim. @@ -121,7 +121,7 @@ vim.opt.breakindent = true -- Save undo history vim.opt.undofile = true --- Case-insensitive searching UNLESS \C or one or more capital letters in the search term +-- Case-insensitive searching UNLESS \C or capital in search vim.opt.ignorecase = true vim.opt.smartcase = true @@ -130,16 +130,13 @@ vim.opt.signcolumn = 'yes' -- Decrease update time vim.opt.updatetime = 250 - --- Decrease mapped sequence wait time --- Displays which-key popup sooner vim.opt.timeoutlen = 300 -- Configure how new splits should be opened vim.opt.splitright = true vim.opt.splitbelow = true --- Sets how neovim will display certain whitespace characters in the editor. +-- Sets how neovim will display certain whitespace in the editor. -- See `:help 'list'` -- and `:help 'listchars'` vim.opt.list = true @@ -161,6 +158,11 @@ vim.opt.scrolloff = 10 vim.opt.hlsearch = true vim.keymap.set('n', '', 'nohlsearch') +-- custom +vim.opt.shell = 'cmd.exe' +vim.opt.autoread = true +vim.opt.expandtab = true + -- 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_next, { desc = 'Go to next [D]iagnostic message' }) @@ -176,10 +178,10 @@ vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagn vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) -- TIP: Disable arrow keys in normal mode --- vim.keymap.set('n', '', 'echo "Use h to move!!"') --- vim.keymap.set('n', '', 'echo "Use l to move!!"') --- vim.keymap.set('n', '', 'echo "Use k to move!!"') --- vim.keymap.set('n', '', 'echo "Use j to move!!"') +vim.keymap.set('n', '', 'echo "Use h to move!!"') +vim.keymap.set('n', '', 'echo "Use l to move!!"') +vim.keymap.set('n', '', 'echo "Use k to move!!"') +vim.keymap.set('n', '', 'echo "Use j to move!!"') -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windows @@ -190,6 +192,15 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +vim.keymap.set('n', '0', '^') + +vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { + group = vim.api.nvim_create_augroup('custom-cursor-remember', { clear = true }), + desc = 'return cursor to where it was last time closing the file', + pattern = '*', + command = 'silent! normal! g`"zv', +}) + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -213,6 +224,8 @@ if not vim.loop.fs_stat(lazypath) then end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) +vim.g.editorconfig = true + -- [[ Configure and install plugins ]] -- -- To check the current status of your plugins, run @@ -220,7 +233,7 @@ vim.opt.rtp:prepend(lazypath) -- -- 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 -- -- NOTE: Here is where you install your plugins. @@ -241,7 +254,7 @@ require('lazy').setup({ { 'numToStr/Comment.nvim', opts = {} }, -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. This is equivalent to the following Lua: + -- options to `gitsigns.nvim`. This is equivalent to the following lua: -- require('gitsigns').setup({ ... }) -- -- See `:help gitsigns` to understand what the configuration keys do @@ -258,7 +271,7 @@ require('lazy').setup({ }, }, - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. + -- 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. @@ -303,21 +316,11 @@ require('lazy').setup({ branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', - { -- If encountering errors, see telescope-fzf-native README for installation instructions + { 'nvim-telescope/telescope-fzf-native.nvim', - - -- `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', - - -- `cond` is a condition used to determine whether this plugin should be - -- installed and loaded. - cond = function() - return vim.fn.executable 'make' == 1 - end, + build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', }, { 'nvim-telescope/telescope-ui-select.nvim' }, - -- Useful for getting pretty icons, but requires a Nerd Font. { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, @@ -326,19 +329,19 @@ require('lazy').setup({ -- 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: + -- 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 + -- 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: + -- 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 + -- telescope picker. This is really useful to discover what Telescope can -- do as well as how to actually do it! -- [[ Configure Telescope ]] @@ -360,7 +363,7 @@ require('lazy').setup({ }, } - -- Enable Telescope extensions if they are installed + -- Enable telescope extensions, if they are installed pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') @@ -379,14 +382,14 @@ require('lazy').setup({ -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. + -- 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' }) - -- It's also possible to pass additional configuration options. + -- Also possible to pass additional configuration options. -- See `:help telescope.builtin.live_grep()` for information about particular keys vim.keymap.set('n', 's/', function() builtin.live_grep { @@ -395,7 +398,7 @@ require('lazy').setup({ } end, { desc = '[S]earch [/] in Open Files' }) - -- Shortcut for searching your Neovim configuration 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' }) @@ -405,7 +408,7 @@ require('lazy').setup({ { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim + -- Automatically install LSPs and related tools to stdpath for neovim 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', @@ -413,21 +416,17 @@ require('lazy').setup({ -- Useful status updates for LSP. -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', opts = {} }, - - -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - { 'folke/neodev.nvim', opts = {} }, }, config = function() - -- Brief aside: **What is LSP?** + -- Brief Aside: **What is LSP?** -- - -- LSP is an initialism you've probably heard, but might not understand what it is. + -- 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 + -- 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! -- @@ -451,8 +450,9 @@ require('lazy').setup({ vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), callback = function(event) - -- 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. + -- 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. @@ -462,7 +462,7 @@ require('lazy').setup({ -- 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 . + -- To jump back, press . map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') -- Find references for the word under your cursor. @@ -481,11 +481,11 @@ require('lazy').setup({ -- Symbols are things like variables, functions, types, etc. map('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 entire project. + -- Fuzzy find all the symbols in your current workspace + -- Similar to document symbols, except searches over your whole project. map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - -- Rename the variable under your cursor. + -- Rename the variable under your cursor -- Most Language Servers support renaming across files, etc. map('rn', vim.lsp.buf.rename, '[R]e[n]ame') @@ -494,11 +494,11 @@ require('lazy').setup({ map('ca', vim.lsp.buf.code_action, '[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') -- WARN: This is not Goto Definition, this is Goto Declaration. - -- For example, in C this would take you to the header. + -- For example, in C this would take you to the header map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') -- The following two autocommands are used to highlight references of the @@ -522,7 +522,7 @@ require('lazy').setup({ }) -- 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. -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers. local capabilities = vim.lsp.protocol.make_client_capabilities() @@ -538,6 +538,7 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { + -- jsonls = {}, -- clangd = {}, -- gopls = {}, -- pyright = {}, @@ -553,10 +554,22 @@ require('lazy').setup({ lua_ls = { -- cmd = {...}, - -- filetypes = { ...}, + -- filetypes { ...}, -- capabilities = {}, settings = { Lua = { + runtime = { version = 'LuaJIT' }, + workspace = { + checkThirdParty = false, + -- Tells lua_ls where to find all the Lua files that you have loaded + -- for your neovim configuration. + library = { + '${3rd}/luv/library', + unpack(vim.api.nvim_get_runtime_file('', true)), + }, + -- If lua_ls is really slow on your computer, you can try this instead: + -- library = { vim.env.VIMRUNTIME }, + }, completion = { callSnippet = 'Replace', }, @@ -572,14 +585,14 @@ require('lazy').setup({ -- other tools, you can run -- :Mason -- - -- You can press `g?` for help in this menu. + -- You can press `g?` for help in this menu require('mason').setup() -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code + 'stylua', -- Used to format lua code }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } @@ -600,20 +613,17 @@ require('lazy').setup({ { -- Autoformat 'stevearc/conform.nvim', + event = { 'BufReadPre', 'BufNewFile' }, opts = { notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - return { - timeout_ms = 500, - lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], - } - end, + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, formatters_by_ft = { lua = { 'stylua' }, + yaml = { 'prettier' }, + -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- @@ -632,25 +642,14 @@ require('lazy').setup({ { 'L3MON4D3/LuaSnip', build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. + -- Build Step is needed for regex support in snippets + -- This step is not supported in many windows environments + -- Remove the below condition to re-enable on windows if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end return 'make install_jsregexp' end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, }, 'saadparwaiz1/cmp_luasnip', @@ -659,6 +658,12 @@ require('lazy').setup({ -- into multiple repos for maintenance purposes. 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', + + -- If you want to add a bunch of pre-configured snippets, + -- you can use this plugin to help you. It even has snippets + -- for various frameworks/libraries/etc. but you will have to + -- set up the ones that are useful for you. + -- 'rafamadriz/friendly-snippets', }, config = function() -- See `:help cmp` @@ -684,10 +689,6 @@ require('lazy').setup({ -- Select the [p]revious item [''] = cmp.mapping.select_prev_item(), - -- Scroll the documentation window [b]ack / [f]orward - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - -- Accept ([y]es) the completion. -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. @@ -716,9 +717,6 @@ require('lazy').setup({ luasnip.jump(-1) end end, { 'i', 's' }), - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, sources = { { name = 'nvim_lsp' }, @@ -731,18 +729,19 @@ 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. + -- 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`. + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme` 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() + 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 + config = function() -- Load the colorscheme here. -- Like many other themes, this one has different styles, and you could load -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. vim.cmd.colorscheme 'tokyonight-night' - -- You can configure highlights by doing something like: + -- You can configure highlights by doing something like vim.cmd.hi 'Comment gui=none' end, }, @@ -787,27 +786,21 @@ require('lazy').setup({ -- Check out: https://github.com/echasnovski/mini.nvim end, }, + { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', - opts = { - ensure_installed = { 'bash', 'c', 'html', 'lua', 'markdown', 'vim', 'vimdoc' }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. - additional_vim_regex_highlighting = { 'ruby' }, - }, - indent = { enable = true, disable = { 'ruby' } }, - }, - config = function(_, opts) + config = function() -- [[ Configure Treesitter ]] See `:help nvim-treesitter` ---@diagnostic disable-next-line: missing-fields - require('nvim-treesitter.configs').setup(opts) + require('nvim-treesitter.configs').setup { + ensure_installed = { 'bash', 'c', 'html', 'lua', 'markdown', 'vim', 'vimdoc' }, + -- Autoinstall languages that are not installed + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + } -- There are additional nvim-treesitter modules that you can use to interact -- with nvim-treesitter. You should go explore a few and see what interests you: @@ -820,27 +813,26 @@ require('lazy').setup({ -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the -- init.lua. If you want these files, they are in the repository, so you can just download them and - -- place them in the correct locations. + -- 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 plugins for kickstart -- - -- Here are some example plugins that I've included in the Kickstart repository. + -- Here are some example plugins that I've included in the kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', + require 'kickstart.plugins.indent_line', -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { - -- If you are using a Nerd Font: set icons to an empty table which will use the - -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table + -- If you have a Nerd Font, set icons to an empty table which will use the + -- default lazy.nvim defined Nerd Font icons otherwise define a unicode icons table icons = vim.g.have_nerd_font and {} or { cmd = '⌘', config = '🛠',