-- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, 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) -- Make sure to setup `mapleader` and `maplocalleader` before -- loading lazy.nvim so that mappings are correct. -- This is also a good place to setup other settings (vim.opt) vim.g.mapleader = " " vim.g.maplocalleader = "," -- Setup lazy.nvim require("lazy").setup({ spec = { -- import your plugins { import = "plugins" }, }, -- automatically check for plugin updates checker = { enabled = true, notify = false }, }) -- skip backwards compatibility routines and speed up loading vim.g.skip_ts_context_commentstring_module = true vim.g.markdown_fenced_languages = { "ts=typescript", } -- VARIOUS AUTOCMDS HERE vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "qf", "help", "man", "lspinfo", "spectre_panel" }, callback = function() vim.cmd([[ nnoremap q :close set nobuflisted ]]) end, }) vim.api.nvim_create_autocmd({ "FileType" }, { pattern = { "gitcommit", "markdown" }, callback = function() vim.opt_local.spell = true vim.opt_local.wrap = true end, }) vim.api.nvim_create_autocmd({ "VimResized" }, { callback = function() vim.cmd("tabdo wincmd =") end, }) vim.api.nvim_create_autocmd({ "CmdWinEnter" }, { callback = function() vim.cmd("quit") end, }) vim.api.nvim_create_autocmd({ "TextYankPost" }, { callback = function() vim.highlight.on_yank({ higroup = "Visual", timeout = 200 }) end, }) vim.api.nvim_create_user_command("CopyRelPath", function() local path = vim.fn.expand("%") vim.fn.setreg("+", path) vim.notify('Copied "' .. path .. '" to the clipboard!') end, {}) -- remember folds vim.cmd([[ augroup remember_folds autocmd! autocmd BufWinLeave *.* mkview autocmd BufWinEnter *.* silent! loadview augroup END ]]) vim.api.nvim_create_autocmd({ "BufWritePost" }, { pattern = { "*.java" }, callback = function() vim.lsp.codelens.refresh() end, }) vim.api.nvim_create_autocmd({ "BufWritePre" }, { callback = function() vim.cmd("StripTrailingWhitespace") end, }) vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*.tf", "*.tfvars" }, callback = function() vim.lsp.buf.format() end, }) vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { pattern = "deployment.yaml", callback = function() vim.opt_local.filetype = "helm" end, }) ---@type table local progress = vim.defaulttable() vim.api.nvim_create_autocmd("LspProgress", { ---@param ev {data: {client_id: integer, params: lsp.ProgressParams}} callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) local value = ev.data.params.value --[[@as {percentage?: number, title?: string, message?: string, kind: "begin" | "report" | "end"}]] if not client or type(value) ~= "table" then return end local p = progress[client.id] for i = 1, #p + 1 do if i == #p + 1 or p[i].token == ev.data.params.token then p[i] = { token = ev.data.params.token, msg = ("[%3d%%] %s%s"):format( value.kind == "end" and 100 or value.percentage or 100, value.title or "", value.message and (" **%s**"):format(value.message) or "" ), done = value.kind == "end", } break end end local msg = {} ---@type string[] progress[client.id] = vim.tbl_filter(function(v) return table.insert(msg, v.msg) or not v.done end, p) local spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" } vim.notify(table.concat(msg, "\n"), "info", { id = "lsp_progress", title = client.name, opts = function(notif) notif.icon = #progress[client.id] == 0 and " " or spinner[math.floor(vim.uv.hrtime() / (1e6 * 80)) % #spinner + 1] end, }) end, }) -- KEYMAPS -- Shorten function name local keymap = vim.api.nvim_set_keymap -- Silent keymap option local opts = { silent = true } keymap("v", "y", '"+y', { noremap = true }) -- open oil keymap + autocmd to also open with preview keymap("n", "-", "Oil --float", opts) vim.api.nvim_create_autocmd("User", { pattern = "OilEnter", callback = vim.schedule_wrap(function(args) local oil = require("oil") if vim.api.nvim_get_current_buf() == args.data.buf and oil.get_cursor_entry() then oil.open_preview() end end), }) keymap("n", "c", ":bpspbnbd", { noremap = true, silent = true }) keymap("n", "s", ":vert sb", { noremap = true, silent = true }) keymap("n", "", ":30winc <", opts) keymap("n", "", ":30winc >", opts) keymap("t", "", "", { noremap = true }) -- jump up and down then center -- keymap("n", "", "zz", opts) -- keymap("n", "", "zz", opts) -- save file keymap("n", "", ":w", opts) keymap("i", "", ":w", opts) keymap("n", "fml", "CellularAutomaton make_it_rain", opts) keymap("", "", "", { noremap = true, silent = true }) keymap("", "", "", { noremap = true, silent = true }) keymap("", "", "", { noremap = true, silent = true }) keymap("", "", "", { noremap = true, silent = true }) -- jump back and forth between last two buffers keymap("n", "j", ":b#", opts) -- neotree toggle keymap("n", "n", ":Neotree toggle", opts) -- Modes -- normal_mode = "n", -- insert_mode = "i", -- visual_mode = "v", -- visual_block_mode = "x", -- term_mode = "t", -- command_mode = "c", -- Resize with arrows keymap("n", "", ":resize -2", opts) keymap("n", "", ":resize +2", opts) keymap("n", "", ":vertical resize -2", opts) keymap("n", "", ":vertical resize +2", opts) -- Clear highlights keymap("n", "h", "nohlsearch", opts) -- Better paste keymap("v", "p", '"_dP', opts) -- Insert -- keymap("i", "jk", "", opts) -- Press jk fast to enter keymap("v", "J", ":m '>+1gv=gv", opts) -- Shift visual selected line down keymap("v", "K", ":m '<-2gv=gv", opts) -- Shift visual selected line up -- Visual -- -- Stay in indent mode keymap("v", "<", "", ">gv", opts) vim.o.jumpoptions = "" -- OPTIONS vim.opt.clipboard = "" vim.opt.colorcolumn = "80,120" vim.opt.relativenumber = true vim.opt.shiftwidth = 4 vim.opt.tabstop = 4 vim.opt.title = false vim.o.background = "dark" vim.o.exrc = true -- enable project local config vim.opt.backup = false -- creates a backup file vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages vim.opt.completeopt = { "menuone", "noselect" } -- mostly just for cmp vim.opt.conceallevel = 1 -- i hate anything being concealed, it's weird (set to 1 for obsidian.nvim) vim.opt.cursorline = true -- highlight the current line vim.opt.expandtab = true -- convert tabs to spaces vim.opt.fileencoding = "utf-8" -- the encoding written to a file vim.opt.fillchars.eob = " " -- show empty lines at the end of a buffer as ` ` {default `~`} vim.opt.formatoptions:remove({ "c", "r", "o" }) -- This is a sequence of letters which describes how automatic formatting is to be done vim.opt.hlsearch = true -- highlight all matches on previous search pattern vim.opt.ignorecase = true -- ignore case in search patterns vim.opt.iskeyword:append("-") -- treats words with `-` as single words vim.opt.laststatus = 3 -- only the last window will always have a status line vim.opt.linebreak = true vim.opt.list = true vim.opt.listchars = { eol = "↲", tab = ">-", } vim.opt.mouse = "a" -- allow the mouse to be used in neovim vim.opt.number = true -- set numbered lines vim.opt.numberwidth = 4 -- minimal number of columns to use for the line number {default 4} vim.opt.pumheight = 10 -- pop up menu height vim.opt.ruler = false -- hide the line and column number of the cursor position vim.opt.scrolloff = 8 -- minimal number of screen lines to keep above and below the cursor vim.opt.shortmess:append("c") -- hide all the completion messages, e.g. "-- XXX completion (YYY)", "match 1 of 2", "The only match", "Pattern not found" vim.opt.showcmd = false -- hide (partial) command in the last line of the screen (for performance) vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore vim.opt.showtabline = 0 -- always show tabs vim.opt.sidescrolloff = 8 -- minimal number of screen columns to keep to the left and right of the cursor if wrap is `false` vim.opt.signcolumn = "yes" -- always show the sign column, otherwise it would shift the text each time vim.opt.smartcase = true -- smart case vim.opt.smartindent = true -- make indenting smarter again vim.opt.splitbelow = true -- force all horizontal splits to go below current window vim.opt.splitright = true -- force all vertical splits to go to the right of current window vim.opt.swapfile = false -- creates a swapfile vim.opt.termguicolors = true -- set term gui colors (most terminals support this) vim.opt.timeoutlen = 500 -- time to wait for a mapped sequence to complete (in milliseconds) vim.opt.undofile = true -- enable persistent undo vim.opt.updatetime = 200 -- faster completion (4000ms default) vim.opt.whichwrap:append("<,>,[,],h,l") -- keys allowed to move to the previous/next line when the beginning/end of line is reached vim.opt.wrap = false -- display lines as one long line vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited