---@diagnostic disable: missing-fields -- INFO: introduction -- this is a minimal neovim configuration written in lua. this is not meant to -- be a distribution, but rather a template for you to build upon and/or a -- reference for how to configure neovim using lua in the latest version. -- -- TUTOR: -- if you're completely new to neovim and/or vim, consider going through -- `:Tutor` inside neovim to get a basic idea of how it works. -- if you don't know what this means, type the following: -- - -- - : -- - Tutor -- - -- -- LUA: -- some level of familiarity with lua/programming languages are also expected. -- if you're new to lua, consider going through the official reference: -- https://www.lua.org/manual -- or a more friendly tutorial like: -- https://learnxinyminutes.com/docs/lua/ -- you can also check out `:h lua-guide` inside neovim for a neovim-specific -- lua guide. -- -- DEPENDENCIES: -- this configuration assumes you have the following tools installed on your -- system: -- `git` - for vim builtin package manager. (see `:h vim.pack`) -- `ripgrep` - for fuzzy finding -- clipboard tool: xclip/xsel/win32yank - for clipboard sharing between OS and neovim (see `h: clipboard-tool`) -- a nerdfont (ensure the terminal running neovim is using it) -- run `:checkhealth` inside neovim to see if your system is missing anything. -- -- MINIMAL: -- to say that something is 'minimal' you have to define what variable you're -- minimizing. this configuration minimizes for lines of code and concepts. -- to some, this configuration may have too many plugins. for example, using -- mason.nvim to manage lsp servers will be an unnecessary dependency if the -- user is already familiar with lsps and is comfortable managing them through -- their OS package manager. but to someone that isn't familiar with lsp servers -- this approach wouldn't cover everything needed to have the 'minimum' necessary -- for lsp + completion + fuzzy finding. to some, fuzzy finding is also a bloated -- dependency. -- this configuration is only a starting point/reference. it is expected that -- the user will change the configuration to suit their needs. -- INFO: options -- these change the default neovim behaviours using the 'vim.opt' API. -- see `:h vim.opt` for more details. -- run `:h '{option_name}'` to see what they do and what values they can take. -- for example, `:h 'number'` for `vim.opt.number`. -- set as the leader key -- must happen before plugins are loaded (otherwise wrong leader will be used) vim.g.mapleader = " " vim.g.maplocalleader = " " -- enable true color support vim.opt.termguicolors = true -- make line numbers default vim.opt.number = true vim.opt.relativenumber = true -- enable mouse mode, can be useful for resizing splits vim.opt.mouse = "a" -- sync clipboard between OS and neovim. -- remove this option if you want your OS clipboard to remain independent. -- see `:help 'clipboard'` vim.opt.clipboard = "unnamedplus" -- save undo history vim.opt.undofile = true -- keep signcolumn on by default vim.opt.signcolumn = "yes" -- sets how neovim will display certain whitespace characters in the editor. -- see `:help 'list'` -- and `:help 'listchars'` vim.opt.list = true vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣", } -- enable live preview of substitutions vim.opt.inccommand = "split" -- show which line your cursor is on vim.opt.cursorline = true -- set highlight on search, but clear on pressing in normal mode vim.opt.hlsearch = true -- enable break indent vim.opt.breakindent = true -- enable line wrapping vim.opt.wrap = true -- formatting vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.opt.expandtab = true vim.opt.textwidth = 80 vim.diagnostic.config({ signs = { text = { [vim.diagnostic.severity.ERROR] = " ", [vim.diagnostic.severity.WARN] = " ", [vim.diagnostic.severity.INFO] = " ", [vim.diagnostic.severity.HINT] = " ", }, }, virtual_text = true, -- show inline diagnostics }) -- clear search highlights with vim.keymap.set("n", "", "nohlsearch") -- INFO: colorscheme vim.cmd.colorscheme("catppuccin") -- INFO: plugins -- we install plugins with neovim's builtin package manager: vim.pack -- and then enable/configure them by calling their setup functions. -- -- (see `:h vim.pack` for more details on how it works) -- you can press `gx` on any of the plugin urls below to open them in your -- browser and check out their documentation and functionality. -- alternatively, you can run `:h {plugin-name}` to read their documentation. -- -- plugins are then loaded and configured with a call to `setup` functions -- provided by each plugin. this is not a rule of neovim but rather a convention -- followed by the community. -- these setup calls take a table as an agument and their expected contents can -- vary wildly. refer to each plugin's documentation for details. -- INFO: formatting and syntax highlighting vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter" }, { confirm = false }) -- equivalent to :TSUpdate require("nvim-treesitter.install").update("all") require("nvim-treesitter.configs").setup({ auto_install = true, -- autoinstall languages that are not installed yet }) -- INFO: completion engine vim.pack.add({ "https://github.com/saghen/blink.cmp" }, { confirm = false }) require("blink.cmp").setup({ completion = { documentation = { auto_show = true, }, }, -- default blink keymaps keymap = { [''] = { 'select_prev', 'fallback_to_mappings' }, [''] = { 'select_next', 'fallback_to_mappings' }, [''] = { 'select_and_accept', 'fallback' }, [''] = { 'cancel', 'fallback' }, [''] = { 'show', 'show_documentation', 'hide_documentation' }, [''] = { 'snippet_forward', 'fallback' }, [''] = { 'snippet_backward', 'fallback' }, [''] = { 'scroll_documentation_up', 'fallback' }, [''] = { 'scroll_documentation_down', 'fallback' }, [''] = { 'show_signature', 'hide_signature', 'fallback' }, }, fuzzy = { implementation = "lua", }, }) -- INFO: lsp server installation and configuration -- lsp servers we want to use and their configuration -- see `:h lspconfig-all` for available servers and their settings local lsp_servers = { lua_ls = { -- https://luals.github.io/wiki/settings/ | `:h nvim_get_runtime_file` Lua = { workspace = { library = vim.api.nvim_get_runtime_file("lua", true) }, }, }, clangd = {}, rust_analyzer = {}, gopls = {}, } vim.pack.add({ "https://github.com/neovim/nvim-lspconfig", -- default configs for lsps -- NOTE: if you'd rather install the lsps through your OS package manager you -- can delete the next three mason-related lines and their setup calls below. -- see `:h lsp-quickstart` for more details. "https://github.com/mason-org/mason.nvim", -- package manager "https://github.com/mason-org/mason-lspconfig.nvim", -- lspconfig bridge "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim" -- auto installer }, { confirm = false }) require("mason").setup() require("mason-lspconfig").setup() require("mason-tool-installer").setup({ ensure_installed = vim.tbl_keys(lsp_servers), }) -- configure each lsp server on the table -- to check what clients are attached to the current buffer, use -- `:checkhealth vim.lsp`. to view default lsp keybindings, use `:h lsp-defaults`. for server, config in pairs(lsp_servers) do vim.lsp.config(server, { settings = config, -- only create the keymaps if the server attaches successfully on_attach = function(_, bufnr) vim.keymap.set("n", "grd", vim.lsp.buf.definition, { buffer = bufnr, desc = "vim.lsp.buf.definition()", }) vim.keymap.set("n", "grf", vim.lsp.buf.format, { buffer = bufnr, desc = "vim.lsp.buf.format()", }) end, }) end -- INFO: fuzzy finder vim.pack.add({ "https://github.com/nvim-lua/plenary.nvim", -- library dependency "https://github.com/nvim-tree/nvim-web-devicons", -- icons (nerd font) "https://github.com/nvim-telescope/telescope.nvim" -- the fuzzy finder }, { confirm = false }) require("telescope").setup({}) local pickers = require("telescope.builtin") vim.keymap.set("n", "sp", pickers.builtin, { desc = "[S]earch Builtin [P]ickers", }) vim.keymap.set("n", "sb", pickers.buffers, { desc = "[S]earch [B]uffers", }) vim.keymap.set("n", "sf", pickers.find_files, { desc = "[S]earch [F]iles", }) vim.keymap.set("n", "sw", pickers.grep_string, { desc = "[S]earch Current [W]ord", }) vim.keymap.set("n", "sg", pickers.live_grep, { desc = "[S]earch by [G]rep", }) vim.keymap.set("n", "sr", pickers.resume, { desc = "[S]earch [R]esume", }) vim.keymap.set("n", "sh", pickers.help_tags, { desc = "[S]earch [H]elp", }) vim.keymap.set("n", "sm", pickers.man_pages, { desc = "[S]earch [M]anuals", }) -- INFO: keybinding helper vim.pack.add({ "https://github.com/folke/which-key.nvim" }, { confirm = false }) require("which-key").setup({ spec = { { "s", group = "[S]earch", icon = { icon = "", color = "green", }, }, } }) -- uncomment to enable automatic plugin updates -- vim.pack.update()