-- 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 = " " -- Disable mouse input vim.o.mouse = "" -- Print the line number in front of each line vim.o.number = true local numbertoggle_group = vim.api.nvim_create_augroup("numbertoggle", {}) vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, { pattern = "*", group = numbertoggle_group, callback = function() if vim.o.nu and vim.api.nvim_get_mode().mode ~= "i" then vim.opt.relativenumber = true end end, }) vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, { pattern = "*", group = numbertoggle_group, callback = function() if vim.o.nu then vim.opt.relativenumber = false -- Conditional taken from https://github.com/rockyzhang24/dotfiles/commit/03dd14b5d43f812661b88c4660c03d714132abcf -- Workaround for https://github.com/neovim/neovim/issues/32068 if not vim.tbl_contains({ "@", "-" }, vim.v.event.cmdtype) then vim.cmd("redraw") end end end, }) -- 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.api.nvim_create_autocmd("UIEnter", { callback = function() vim.o.clipboard = "unnamedplus" end, }) vim.o.termguicolors = true vim.cmd.colorscheme("gruvbox") -- Highlight the line where the cursor is on vim.o.cursorline = true -- Column at 80 characters vim.o.colorcolumn = "80" -- Minimal number of screen lines to keep above and below the cursor. vim.o.scrolloff = 10 -- Set default tabstop and shiftwidth vim.o.tabstop = 4 vim.o.shiftwidth = 4 -- Show and trailing spaces vim.o.list = true vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } -- Configure line wrap vim.o.linebreak = true vim.o.breakindent = true vim.o.showbreak = "↪ " -- Case-insensitive searching UNLESS \C or one or more capital letters in the search term vim.o.ignorecase = true vim.o.smartcase = true -- Use undofile to preserve actions over restarts vim.o.undofile = true -- 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 -- [[ Set up keymaps ]] See `:h vim.keymap.set()`, `:h mapping`, `:h keycodes` -- Use to exit terminal mode vim.keymap.set("t", "", "") -- Map , , , to navigate between windows in any modes vim.keymap.set({ "t", "i" }, "", "h") vim.keymap.set({ "t", "i" }, "", "j") vim.keymap.set({ "t", "i" }, "", "k") vim.keymap.set({ "t", "i" }, "", "l") vim.keymap.set({ "n" }, "", "h") vim.keymap.set({ "n" }, "", "j") vim.keymap.set({ "n" }, "", "k") vim.keymap.set({ "n" }, "", "l") -- [[ Basic Autocommands ]]. -- See `:h lua-guide-autocommands`, `:h autocmd`, `:h nvim_create_autocmd()` -- Highlight when yanking (copying) text. -- Try it with `yap` in normal mode. See `:h vim.hl.on_yank()` vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking (copying) text", callback = function() vim.hl.on_yank() end, }) -- [[ Create user commands ]] -- See `:h nvim_create_user_command()` and `:h user-commands` -- Create a command `:GitBlameLine` that print the git blame for the current line vim.api.nvim_create_user_command("GitBlameLine", function() local line_number = vim.fn.line(".") -- Get the current line number. See `:h line()` local filename = vim.api.nvim_buf_get_name(0) print(vim.fn.system({ "git", "blame", "-L", line_number .. ",+1", filename })) end, { desc = "Print the git blame for the current line" }) -- [[ Add optional packages ]] -- Nvim comes bundled with a set of packages that are not enabled by -- default. You can enable any of them by using the `:packadd` command. -- For example, to add the "nohlsearch" package to automatically turn off search highlighting after -- 'updatetime' and when going to insert mode vim.cmd("packadd! nohlsearch") vim.pack.add({"https://github.com/nvim-treesitter/nvim-treesitter"}) require("nvim-treesitter").install('latex', 'lua', 'c', 'ocaml') -- Treat Ipe stylesheets as xml code vim.filetype.add({ extension = { isy = "xml", }, }) -- 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 = {}, texlab = {}, } -- See `:h lsp-quickstart` for more details. vim.pack.add({ "https://github.com/neovim/nvim-lspconfig", -- default configs for lsps "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 }) 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) -- Put mappings here vim.keymap.set( "n", "ld", vim.lsp.buf.definition, { buffer = bufnr, desc = "vim.lsp.buf.definition()" } ) vim.keymap.set("n", "lf", vim.lsp.buf.format, { buffer = bufnr, desc = "vim.lsp.buf.format()" }) end, }) end vim.diagnostic.config({ signs = { text = { [vim.diagnostic.severity.ERROR] = "W ", [vim.diagnostic.severity.WARN] = "w ", [vim.diagnostic.severity.INFO] = "I ", [vim.diagnostic.severity.HINT] = "H ", }, }, virtual_text = true, -- Show inline diagnostics }) vim.keymap.set("n", "dn", "]d", {desc = "Jump to next diagnostic"}) vim.keymap.set("n", "dp", "[d", {desc = "Jump to previous diagnostic"}) vim.keymap.set("n", "dN", "]D", {desc = "Jump to last diagnostic"}) vim.keymap.set("n", "dP", "[D", {desc = "Jump to first diagnostic"}) vim.keymap.set("n", "ds", "d", {desc = "Display diagnostic on current line"}) vim.pack.add({ "https://github.com/nvim-mini/mini.completion", "https://github.com/nvim-mini/mini.snippets", "https://github.com/nvim-mini/mini.icons", "https://github.com/nvim-mini/mini.statusline", "https://github.com/nvim-mini/mini-git", "https://github.com/nvim-mini/mini.diff", "https://github.com/nvim-mini/mini.clue", "https://github.com/nvim-mini/mini.hipatterns", "https://github.com/nvim-mini/mini.notify", }, { confirm = false }) vim.o.winborder = "none" -- Use mini.completion require("mini.completion").setup() -- Snipped integration for mini.completion require("mini.snippets").setup() -- Icons for statusline and completion require("mini.icons").setup() -- Use mini.statusline instead of native showmode require("mini.statusline").setup() vim.o.showmode = false -- Git integration for statusline and Command mode require("mini.git").setup() -- Show git diff in linenumbers require("mini.diff").setup() -- Use and configure mini.clue local miniclue = require("mini.clue") miniclue.setup({ triggers = { -- Leader triggers { mode = { "n", "x" }, keys = "" }, -- `[` and `]` keys { mode = "n", keys = "[" }, { mode = "n", keys = "]" }, -- Built-in completion { mode = "i", keys = "" }, -- `g` key { mode = { "n", "x" }, keys = "g" }, -- Marks { mode = { "n", "x" }, keys = "'" }, { mode = { "n", "x" }, keys = "`" }, -- Registers { mode = { "n", "x" }, keys = '"' }, { mode = { "i", "c" }, keys = "" }, -- Window commands { mode = "n", keys = "" }, -- `z` key { mode = { "n", "x" }, keys = "z" }, }, clues = { -- Enhance this by adding descriptions for mapping groups miniclue.gen_clues.square_brackets(), miniclue.gen_clues.builtin_completion(), miniclue.gen_clues.g(), miniclue.gen_clues.marks(), miniclue.gen_clues.registers(), miniclue.gen_clues.windows(), miniclue.gen_clues.z(), }, window = { delay = 200, config = { width = 'auto', } } }) -- Use and configure mini.hipatterns local hipatterns = require('mini.hipatterns') hipatterns.setup({ highlighters = { -- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE' fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' }, hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' }, todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' }, note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' }, -- Highlight hex color strings (`#rrggbb`) using that color hex_color = hipatterns.gen_highlighter.hex_color(), }, }) -- Use mini.notify require("mini.notify").setup()