Something went wrong. Try again.
My personal configuration files and scripts.
Something went wrong. Try again.
18 kB · 691 lines
Lua
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692-- Preamble ⦃
-- Add a more convenient way of creating key bindings.local function map(mode, lhs, rhs, options) local base_options = { noremap = true, silent = true } vim.keymap.set( mode, lhs, rhs, not options and base_options or vim.tbl_extend("force", base_options, options) )end
-- Bootstrap the plugin manager.local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"if not vim.uv.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath, })endvim.opt.rtp:prepend(lazypath)
-- Set the global leader to SPC and the local leader to SPC m.vim.g.mapleader = " " -- NOTE: Must be set before specifying plugins.vim.g.maplocalleader = " m"
-- ⦄
-- Plugins ⦃
local lazy_config = { performance = { rtp = { -- Prevent loading bundled plugins that are not required or superseded by -- other plugins. disabled_plugins = { "gzip", "matchit", "matchparen", "netrwPlugin", "tarPlugin", "tohtml", "tutor", "zipPlugin", }, }, },}
require("lazy").setup({ -- Libraries ⦃ { "nvim-lua/plenary.nvim", name = "plenary" }, -- ⦄
-- Visuals ⦃ { "catppuccin/nvim", name = "catppuccin", priority = 1000, opts = { show_end_of_buffer = true, dim_inactive = { enabled = true }, custom_highlights = function(colors) return { -- Make the background for folds slightly more muted than the default -- of `colors.surface1`. Folded = { bg = colors.surface0 }, } end, }, }, { "nvim-lualine/lualine.nvim", event = "VeryLazy", dependencies = { "kyazdani42/nvim-web-devicons" }, opts = { options = { theme = "catppuccin", section_separators = { left = "", right = "" }, -- Only display one 'global' status line rather than one per window. globalstatus = true, }, sections = { lualine_a = { { "mode", separator = { left = "" }, right_padding = 2 }, }, lualine_b = { "filename", "branch" }, lualine_c = {}, lualine_x = {}, lualine_y = { "filetype", { "fileformat", separator = { right = "" }, padding = { left = 1, right = 0 }, }, "encoding", "progress", }, lualine_z = { { "location", separator = { right = "" }, left_padding = 2 }, }, }, inactive_sections = { lualine_a = { "filename" }, lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, lualine_z = { "location" }, }, extensions = { "lazy", "mundo", "quickfix" }, }, }, { "stevearc/dressing.nvim", name = "dressing", event = "VeryLazy" }, -- ⦄
-- Interface ⦃ { "folke/persistence.nvim", event = "BufReadPre", -- this will only start session saving when an actual file was opened opts = {}, }, { "folke/which-key.nvim", name = "which-key", config = true, }, { "folke/snacks.nvim", dependencies = { "echasnovski/mini.nvim", version = false }, priority = 1000, lazy = false, opts = { dashboard = { enabled = true }, explorer = { enabled = true }, input = { enabled = true }, picker = { enabled = true }, session = { enabled = true }, statuscolumn = { enabled = true, folds = { -- Display an icon for an open fold. open = true, -- Indicate added, changed, and deleted lines. git_hl = true, }, }, zen = { enabled = true }, }, keys = { { "<leader><leader>", function() Snacks.picker.smart() end, desc = "Smart Find Files", }, { "<leader>,", function() Snacks.picker.buffers() end, desc = "Buffers", }, { "<leader>/", function() Snacks.picker.grep() end, desc = "Grep", }, { "<leader>:", function() Snacks.picker.command_history() end, desc = "Command History", }, { "<leader>n", function() Snacks.picker.notifications() end, desc = "Notification History", }, { "<leader>e", function() Snacks.explorer() end, desc = "File Explorer", },
{ "<leader>fb", function() Snacks.picker.buffers() end, desc = "Buffers", }, { "<leader>fc", function() Snacks.picker.files({ cwd = vim.fn.stdpath("config") }) end, desc = "Find Config File", }, { "<leader>ff", function() Snacks.picker.files() end, desc = "Find Files", }, { "<leader>fg", function() Snacks.picker.git_files() end, desc = "Find Git Files", }, { "<leader>fp", function() Snacks.picker.projects() end, desc = "Projects", }, { "<leader>fr", function() Snacks.picker.recent() end, desc = "Recent", },
{ "<leader>z", function() Snacks.zen() end, desc = "Toggle Zen Mode", }, { "<leader>N", desc = "Neovim News", function() Snacks.win({ file = vim.api.nvim_get_runtime_file("doc/news.txt", false)[1], width = 0.9, height = 0.8, wo = { spell = false, wrap = false, signcolumn = "yes", statuscolumn = " ", conceallevel = 3, }, }) end, }, }, }, { "mikavilpas/yazi.nvim", event = "VeryLazy", dependencies = { "folke/snacks.nvim", lazy = false }, opts = { open_for_directories = true, }, init = function() -- Fake loading the netrw plugin so that the `open_for_directories` option -- functions. vim.g.loaded_netrwPlugin = 1 end, keys = { { "<leader>fb", mode = { "n", "v" }, "<cmd>Yazi<cr>", desc = "Browse files", }, }, }, { "simnalamburt/vim-mundo", cmd = { "MundoShow", "MundoToggle" } }, { "lewis6991/gitsigns.nvim", name = "gitsigns", event = "VeryLazy", config = true, }, { "folke/todo-comments.nvim", dependencies = { "folke/snacks.nvim" }, event = { "BufNewFile", "BufReadPost" }, opts = { search = { pattern = [[\b(KEYWORDS)(\([^\)]*\))?:]] }, highlight = { pattern = [[.*<((KEYWORDS)%(\(.{-1,}\))?):]] }, keywords = { -- This keyword is often used in Rust code to mark comments justifying -- why the code inside an unsafe block is actually safe. SAFETY = { icon = "☢", color = "warning" }, } }, keys = { { "<leader>st", function() Snacks.picker.todo_comments() end, desc = "Todo", }, { "<leader>sT", function() Snacks.picker.todo_comments({ keywords = { "TODO", "FIX", "FIXME" } }) end, desc = "Todo/Fix/Fixme", }, }, }, { "NvChad/nvim-colorizer.lua", name = "colorizer", event = "VeryLazy", opts = { filetypes = { "html", "css", "javascript", "typescript" } }, }, { "rcarriga/nvim-notify", name = "notify", event = "VeryLazy" }, { "folke/noice.nvim", event = "VeryLazy" }, -- ⦄
-- Editing ⦃ { "tmsvg/pear-tree", event = "InsertEnter", init = function() vim.g.pear_tree_smart_openers = 1 vim.g.pear_tree_smart_closers = 1 vim.g.pear_tree_smart_backspace = 1 end, }, { "echasnovski/mini.ai", config = true }, { "echasnovski/mini.comment", config = true }, { "kylechui/nvim-surround", config = true }, { "ggandor/leap.nvim", name = "leap", config = function() require("leap").add_default_mappings() end, }, { "ggandor/leap-spooky.nvim", name = "leap-spooky", config = true }, { "ggandor/flit.nvim", name = "flit", config = true }, -- ⦄
-- Completion and Diagnostics ⦃ -- TODO: Set up completion. --- ⦄
-- Language Support ⦃ { "nvim-treesitter/nvim-treesitter", -- TODO: Remove this once main is the default branch. branch = "main", lazy = false, build = function() local ts = require("nvim-treesitter") ts.install({ "bash", "bibtex", "c", "c_sharp", "cmake", "cpp", "css", "dockerfile", "eex", "elixir", "erlang", "fish", "glsl", "go", "haskell", "heex", "html", "java", "javascript", "jsdoc", "json", "just", "kotlin", "lua", "markdown", "markdown_inline", "meson", "ninja", "nix", "ocaml", "ocaml_interface", "perl", "php", "prolog", "python", "qmljs", "query", "regex", "ruby", "rust", "sql", "svelte", "toml", "typescript", "typst", "vim", "vimdoc", "wgsl", "wit", "yaml", "zig", }) ts.update() end, }, { "Shirk/vim-gas" }, { "lervag/vimtex", ft = "tex" }, { "nvim-neorg/neorg", ft = "norg", config = function() require("neorg").setup({ load = { ["core.defaults"] = {}, ["core.norg.concealer"] = {}, ["core.norg.completion"] = { config = { engine = "nvim-cmp" }, }, ["core.integrations.nvim-cmp"] = {}, }, }) end, }, -- ⦄}, lazy_config)
-- ⦄
-- Visuals ⦃
-- Use 24-bit colour like it's 1995!vim.opt.termguicolors = true
-- Load my default colorscheme of choice.vim.cmd.colorscheme("catppuccin-mocha")
-- The current mode is already displayed in the status line (by Lualine).vim.opt.showmode = false
-- Modify cursor styling so that...vim.opt.guicursor = { -- the normal, visual, command line normal, and show-match modes use a block -- cursor with the default colours defined by the terminal; "n-v-c-sm:block", -- the insert, command line insert, and visual with selection modes use a -- blinking, vertical cursor with colours from the `Cursor` highlight group; "i-ci-ve:ver25-blinkwait700-blinkoff400-blinkon250-Cursor/lCursor", -- the replace, command line replace, and operator-pending modes use a -- blinking, horizontal cursor with colours from the `Cursor` highlight group; "r-cr-o:hor20-blinkwait700-blinkoff400-blinkon250-Cursor/lCursor", -- the built-in terminal uses a blinking, block cursor with colours from the -- `TermCursor` highlight group. "t:block-blinkon500-blinkoff500-TermCursor",}
-- ⦄
-- Interface ⦃
map("n", "<leader>q", ":qa<CR>", { desc = "Quit" })map("n", "<leader>Q", ":qa<CR>", { desc = "Force quit" })
-- Disable arrow keys in normal/visual mode so that I can break the habit.for _, direction in ipairs({ "up", "down", "left", "right" }) do map("", "<" .. direction .. ">", "<nop>")end
-- Set the title of the window if possible.vim.opt.title = true
-- Always display the sign column to avoid unwarranted jumps.vim.opt.signcolumn = "yes"
-- Do not wrap lines longer than the window width.vim.opt.wrap = false
-- Align wrapped lines with the indentation for that line.vim.opt.breakindent = true
-- Enable flash on yank.vim.api.nvim_create_autocmd("TextYankPost", { group = vim.api.nvim_create_augroup("YankFlash", {}), callback = function() vim.highlight.on_yank({ higroup = "Visual", timeout = 300 }) end,})
-- Improve the behaviour of search.vim.opt.ignorecase = truevim.opt.smartcase = truevim.opt.gdefault = true
-- Start scrolling 4 lines before the edge of the window.vim.opt.scrolloff = 4vim.opt.sidescrolloff = 4
-- Enable Tree-Sitter-powered folding and automatically close folds that are 12-- or more levels deep. That much nesting should be fairly rare.vim.opt.foldlevel = 12vim.opt.foldmethod = "expr"vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"vim.opt.fillchars:append({ fold = " " })
-- Enable relative line numbers.vim.opt.number = truevim.opt.relativenumber = true
-- More specifically, use relative line numbers in normal mode and absolute line-- numbers in insert mode.local line_number_group = vim.api.nvim_create_augroup("LineNumber", {})vim.api.nvim_create_autocmd( { "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, { group = line_number_group, callback = function() if vim.opt.number:get() then vim.opt.relativenumber = true end end, })vim.api.nvim_create_autocmd( { "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, { group = line_number_group, callback = function() if vim.opt.number:get() then vim.opt.relativenumber = false end end, })
-- Disable line numbers in the integrated terminal and default to insert mode.vim.api.nvim_create_autocmd("TermOpen", { group = vim.api.nvim_create_augroup("CustomizeTerminal", {}), callback = function() vim.opt_local.number = false vim.opt_local.relativenumber = false
vim.cmd.startinsert() end,})
-- Highlight the line the cursor is on in the currently active buffer.local cursor_line_group = vim.api.nvim_create_augroup("ShowCursorLine", {})vim.api.nvim_create_autocmd({ "VimEnter", "WinEnter", "BufWinEnter" }, { group = cursor_line_group, callback = function() vim.opt_local.cursorline = true end,})vim.api.nvim_create_autocmd({ "WinLeave" }, { group = cursor_line_group, callback = function() vim.opt_local.cursorline = false end,})
-- Jump to the last known cursor position when opening a file, so long as the-- position is still valid and we are not editing a commit message (it's likely-- a different one than last time).vim.api.nvim_create_autocmd("BufReadPost", { group = vim.api.nvim_create_augroup("RestorePosition", {}), callback = function(args) local last_posn = vim.fn.line([['"]])
local is_valid_line = 0 <= last_posn and last_posn <= vim.fn.line("$") -- TODO: Investigate replacing this by more generally excluding such files -- from shada. local is_commit = vim.list_contains({ "commit", "jjdescription" }, vim.b[args.buf].filetype)
if not is_valid_line or is_commit then return end
vim.cmd.normal({ args = { 'g`"' }, bang = true }) -- Deferring this command is somewhat of a hack to ensure that the fold -- containing the cursor is expanded since folds can be created (are -- created?) _after_ the `BufReadPost` event. vim.defer_fn(function() vim.cmd.normal({ args = { "zv" }, bang = true }) end, 5) end,})
-- Automatically create parent directories when saving a file.vim.api.nvim_create_autocmd("BufWritePre", { group = vim.api.nvim_create_augroup("CreateParentDirs", {}), callback = function(event) local file = vim.uv.fs_realpath(event.match) or event.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") local backup = vim.fn.fnamemodify(file, ":p:~:h") backup = backup:gsub("[/\\]", "%%") vim.opt_global.backupext = backup end,})
-- ⦄
-- Editing ⦃
-- Use 2 spaces for indentation.local indent_width = 2vim.opt.tabstop = indent_width -- indenting with tabvim.opt.softtabstop = indent_widthvim.opt.shiftwidth = indent_width -- indenting with >vim.opt.expandtab = true -- use spaces, not tab characters
-- Use 80 characters as the maximum line length.local text_width = 80vim.opt.textwidth = text_widthvim.opt.colorcolumn = { text_width + 1 }
-- Stop the Rust ftplugin from fucking with the above.vim.g.rust_recommended_style = false
-- Delete a level of indentation with Shift+Tab.map("i", "<S-Tab>", "<C-d>")
-- Map Ctrl+Backspace to delete backwards by words.map("i", "<C-BS>", "<C-w>")
-- Display invisible characters.vim.opt.list = truevim.opt.listchars = { tab = "•·", trail = "·", extends = "❯", precedes = "❮", nbsp = "×",}
-- Persist undo history.vim.opt.undofile = true
-- Add dedicated key bindings for yanking to and pasting from the system-- clipboard.map({ "n", "v" }, "<C-y>", '"+y', { desc = "Yank to clipboard" })map({ "n", "v" }, "<C-p>", '"+p', { desc = "Paste from clipboard" })
-- Associate the GLSL filetype with the typical file extensions used for-- shaders.vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { group = vim.api.nvim_create_augroup("AssociateGlsl", {}), pattern = { "*.vert", "*.frag", "*.tesc", "*.geom", "*.comp" }, callback = function() vim.opt_local.filetype = "glsl" end,})
-- ⦄
-- Completion and Diagnostics ⦃
-- Use British English and New Zealand English dictionaries for spell checking.vim.opt.spelllang = { "en_gb", "en_nz" }
-- Enable spell checking.vim.opt.spell = true
-- ⦄
-- vim: set foldlevel=0 foldmethod=marker foldmarker=⦃,⦄: