--[[ ===================================================================== ==================== READ THIS BEFORE CONTINUING ==================== ===================================================================== ======== .-----. ======== ======== .----------------------. | === | ======== ======== |.-""""""""""""""""""-.| |-----| ======== ======== || || | === | ======== ======== || KICKSTART.NVIM || |-----| ======== ======== || || | === | ======== ======== || || |-----| ======== ======== ||:Tutor || |:::::| ======== ======== |'-..................-'| |____o| ======== ======== `"")----------------(""` ___________ ======== ======== /::::::::::| |::::::::::\ \ no mouse \ ======== ======== /:::========| |==hjkl==:::\ \ required \ ======== ======== '""""""""""""' '""""""""""""' '""""""""""' ======== ======== ======== ===================================================================== ===================================================================== What is Kickstart? Kickstart.nvim is *not* a distribution. Kickstart.nvim is a starting point for your own configuration. 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. 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 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 a guide. One possible example which will only take 10-15 minutes: - https://learnxinyminutes.com/docs/lua/ After understanding a bit more about Lua, you can use `:help lua-guide` as a reference for how Neovim integrates Lua. - :help lua-guide - (or HTML version): https://neovim.io/doc/user/lua-guide.html Kickstart Guide: 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: - - : - Tutor - (If you already know 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. 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. 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. 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. NOTE: Look for lines like this Throughout the file. These are for you, the reader, to help you 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. If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. I hope you enjoy your Neovim journey, - TJ P.S. You can delete this when you're done too. It's your config now! :) --]] -- ============================================================ -- SECTION 1: FOUNDATION -- Core Neovim settings, leaders, options, basic keymaps, basic autocmds -- ============================================================ do -- Enable faster startup by caching compiled Lua modules vim.loader.enable() -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` -- NOTE: You can change these options as you wish! -- For more options, you can see `:help option-list` -- Make line numbers default vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! -- vim.o.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' -- Don't show the mode, since it's already in the status line vim.o.showmode = false -- Sync clipboard between OS and Neovim. -- Schedule the setting after `UiEnter` because it can increase startup-time. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` vim.schedule(function() vim.o.clipboard = 'unnamedplus' end) -- Enable break indent vim.o.breakindent = true -- Enable undo/redo changes even after closing and reopening a file vim.o.undofile = true -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term vim.o.ignorecase = true vim.o.smartcase = true -- Keep signcolumn on by default vim.o.signcolumn = 'yes' -- Decrease update time vim.o.updatetime = 250 -- Decrease mapped sequence wait time vim.o.timeoutlen = 300 -- Configure how new splits should be opened vim.o.splitright = true vim.o.splitbelow = true -- Sets how neovim will display certain whitespace characters in the editor. -- See `:help 'list'` -- and `:help 'listchars'` -- -- Notice listchars is set using `vim.opt` instead of `vim.o`. -- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables. -- See `:help lua-options` -- and `:help lua-guide-options` vim.o.list = true vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- Preview substitutions live, as you type! vim.o.inccommand = 'split' -- Show which line your cursor is on vim.o.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. vim.o.scrolloff = 10 -- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), -- instead raise a dialog asking if you wish to save the current file(s) -- See `:help 'confirm'` vim.o.confirm = true -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic Config & Keymaps -- See `:help vim.diagnostic.Opts` vim.diagnostic.config { update_in_insert = false, severity_sort = true, float = { border = 'rounded', source = 'if_many' }, underline = { severity = { min = vim.diagnostic.severity.WARN } }, -- Can switch between these as you prefer virtual_text = true, -- Text shows up at the end of the line virtual_lines = false, -- Text shows up underneath the line, with virtual lines -- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d` jump = { on_jump = function(_, bufnr) vim.diagnostic.open_float { bufnr = bufnr, scope = 'cursor', focus = false, } end, }, } vim.keymap.set('n', '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 -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. -- -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode 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!!"') -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windows -- -- See `:help wincmd` for a list of all window commands vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) -- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes -- vim.keymap.set("n", "", "H", { desc = "Move window to the left" }) -- vim.keymap.set("n", "", "L", { desc = "Move window to the right" }) -- vim.keymap.set("n", "", "J", { desc = "Move window to the lower" }) -- vim.keymap.set("n", "", "K", { desc = "Move window to the upper" }) -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.hl.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), callback = function() vim.hl.on_yank() end, }) end -- ============================================================ -- SECTION 2: PLUGIN MANAGER (lazy.nvim) -- Bootstrap, install, and configure all plugins -- ============================================================ -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' if not (vim.uv or vim.loop).fs_stat(lazypath) then local out = vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', 'https://github.com/folke/lazy.nvim.git', lazypath, }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { 'Failed to clone lazy.nvim:\n', 'ErrorMsg' }, { out, 'WarningMsg' }, { '\nPress any key to exit...' } }, true, {}) vim.fn.getchar() os.exit(1) end end vim.opt.rtp:prepend(lazypath) require('lazy').setup({ spec = { -- ============================================================ -- SECTION 3: UI / CORE UX PLUGINS -- ============================================================ { 'NMAC427/guess-indent.nvim', opts = {} }, { 'nvim-tree/nvim-web-devicons', cond = vim.g.have_nerd_font, }, { 'lewis6991/gitsigns.nvim', opts = { signs = { add = { text = '+' }, change = { text = '~' }, delete = { text = '_' }, topdelete = { text = '‾' }, changedelete = { text = '~' }, }, }, }, { 'folke/which-key.nvim', event = 'VimEnter', opts = { delay = 0, icons = { mappings = vim.g.have_nerd_font }, spec = { { 's', group = '[S]earch', mode = { 'n', 'v' } }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, { 'gr', group = 'LSP Actions', mode = { 'n' } }, }, }, }, { 'folke/todo-comments.nvim', opts = { signs = false } }, { 'nvim-mini/mini.nvim', config = function() require('mini.ai').setup { mappings = { around_next = 'aa', inside_next = 'ii' }, n_lines = 500, } require('mini.surround').setup() local statusline = require 'mini.statusline' statusline.setup { use_icons = vim.g.have_nerd_font } ---@diagnostic disable-next-line: duplicate-set-field statusline.section_location = function() return '%2l:%-2v' end end, }, -- ============================================================ -- SECTION 4: SEARCH & NAVIGATION -- ============================================================ { 'nvim-lua/plenary.nvim' }, { 'nvim-telescope/telescope.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim', 'nvim-telescope/telescope-ui-select.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make', cond = vim.fn.executable('make') == 1, }, }, config = function() require('telescope').setup { extensions = { ['ui-select'] = { require('telescope.themes').get_dropdown() }, }, } pcall(require('telescope').load_extension, 'fzf') pcall(require('telescope').load_extension, 'ui-select') 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', 'v' }, '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', 'sc', builtin.commands, { desc = '[S]earch [C]ommands' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }), callback = function(event) local buf = event.buf vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' }) vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' }) vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' }) vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' }) vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' }) vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' }) end, }) vim.keymap.set('n', '/', function() builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false }) end, { desc = '[/] Fuzzily search in current buffer' }) 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' }) vim.keymap.set('n', 'sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' }) end, }, -- ============================================================ -- SECTION 5: LSP -- ============================================================ { 'j-hui/fidget.nvim', opts = {} }, { 'neovim/nvim-lspconfig', dependencies = { 'mason-org/mason.nvim', 'mason-org/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', }, config = function() vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), callback = function(event) local map = function(keys, func, desc, mode) mode = mode or 'n' vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) end map('grn', vim.lsp.buf.rename, '[R]e[n]ame') map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client:supports_method('textDocument/documentHighlight', event.buf) then local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) vim.api.nvim_create_autocmd('LspDetach', { group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), callback = function(event2) vim.lsp.buf.clear_references() vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } end, }) end if client and client:supports_method('textDocument/inlayHint', event.buf) then map('th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') end end, }) ---@type table local servers = { -- clangd = {}, -- gopls = {}, -- pyright = {}, -- rust_analyzer = {}, -- ts_ls = {}, stylua = {}, lua_ls = { on_init = function(client) client.server_capabilities.documentFormattingProvider = false if client.workspace_folders then local path = client.workspace_folders[1].name if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end end client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { runtime = { version = 'LuaJIT', path = { 'lua/?.lua', 'lua/?/init.lua' }, }, workspace = { checkThirdParty = false, library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), { '${3rd}/luv/library', '${3rd}/busted/library', }), }, }) end, ---@type lspconfig.settings.lua_ls settings = { Lua = { format = { enable = false } }, }, }, } require('mason').setup {} local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { -- Add extra Mason tools here }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } for name, server in pairs(servers) do vim.lsp.config(name, server) vim.lsp.enable(name) end end, }, -- ============================================================ -- SECTION 6: FORMATTING -- ============================================================ { 'stevearc/conform.nvim', config = function() require('conform').setup { notify_on_error = false, format_on_save = function(bufnr) local enabled_filetypes = { -- lua = true, -- python = true, } if enabled_filetypes[vim.bo[bufnr].filetype] then return { timeout_ms = 500 } else return nil end end, default_format_opts = { lsp_format = 'fallback', }, formatters_by_ft = { -- rust = { 'rustfmt' }, -- python = { "isort", "black" }, -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, } vim.keymap.set({ 'n', 'v' }, 'f', function() require('conform').format { async = true } end, { desc = '[F]ormat buffer' }) end, }, -- ============================================================ -- SECTION 7: AUTOCOMPLETE & SNIPPETS -- ============================================================ { 'L3MON4D3/LuaSnip', version = '2.*', build = (vim.fn.has('win32') ~= 1 and vim.fn.executable('make') == 1) and 'make install_jsregexp' or nil, config = function() require('luasnip').setup {} -- vim.pack.add { gh 'rafamadriz/friendly-snippets' } -- require('luasnip.loaders.from_vscode').lazy_load() end, }, { 'saghen/blink.cmp', version = '1.*', dependencies = { 'L3MON4D3/LuaSnip' }, opts = { keymap = { preset = 'default' }, appearance = { nerd_font_variant = 'mono' }, completion = { documentation = { auto_show = false, auto_show_delay_ms = 500 }, }, sources = { default = { 'lsp', 'path', 'snippets' } }, snippets = { preset = 'luasnip' }, fuzzy = { implementation = 'lua' }, signature = { enabled = true }, }, }, -- ============================================================ -- SECTION 8: TREESITTER -- ============================================================ { 'nvim-treesitter/nvim-treesitter', branch = 'main', build = ':TSUpdate', config = function() local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'python', 'query', 'sql', 'vim', 'vimdoc' } require('nvim-treesitter').install(parsers, function(lang, success) if success then vim.notify('treesitter: installed ' .. lang, vim.log.levels.INFO) else vim.notify('treesitter: failed to install ' .. lang, vim.log.levels.WARN) end end) ---@param buf integer ---@param language string local function treesitter_try_attach(buf, language) if not vim.treesitter.language.add(language) then return end vim.treesitter.start(buf, language) -- vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -- vim.wo.foldmethod = 'expr' local has_indent_query = vim.treesitter.query.get(language, 'indents') ~= nil if has_indent_query then vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end end local available_parsers = require('nvim-treesitter').get_available() vim.api.nvim_create_autocmd('FileType', { callback = function(args) local buf, filetype = args.buf, args.match local language = vim.treesitter.language.get_lang(filetype) if not language then return end local installed_parsers = require('nvim-treesitter').get_installed 'parsers' if vim.tbl_contains(installed_parsers, language) then treesitter_try_attach(buf, language) elseif vim.tbl_contains(available_parsers, language) then require('nvim-treesitter').install(language):await(function() treesitter_try_attach(buf, language) end) else treesitter_try_attach(buf, language) end end, }) end, }, -- ============================================================ -- SECTION 9: KICKSTART OPTIONAL PLUGINS -- ============================================================ { import = 'kickstart.plugins.indent_line' }, { import = 'kickstart.plugins.lint' }, -- { import = 'kickstart.plugins.debug' }, -- { import = 'kickstart.plugins.autopairs' }, -- { import = 'kickstart.plugins.neo-tree' }, { import = 'kickstart.plugins.gitsigns' }, -- ============================================================ -- CUSTOM PLUGINS -- ============================================================ { import = 'custom.plugins' }, }, install = { colorscheme = { 'gruvbox-medium', 'habamax' } }, checker = { enabled = false }, }) -- Open Oil in a floating window vim.keymap.set("n", "of", "Oil --float", { desc = "Open Oil float" }) -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et