local github = function(repo) return "https://github.com/" .. repo end vim.g.mapleader = "," vim.opt.winborder = "rounded" vim.opt.relativenumber = true vim.opt.number = true vim.opt.spelllang = "en" -- Global options vim.opt.termguicolors = true vim.opt.hidden = true vim.opt.hlsearch = false vim.opt.incsearch = true vim.opt.scrolloff = 8 vim.opt.splitright = true local tab_value = 4 vim.opt.tabstop = tab_value vim.opt.softtabstop = tab_value vim.opt.shiftwidth = tab_value vim.opt.expandtab = true vim.opt.shell = "fish" vim.opt.bg = "dark" vim.opt.spell = false -- Enables treesitter comment spelling vim.opt.termguicolors = true vim.opt.signcolumn = "yes" vim.opt.filetype = "on" vim.o.swapfile = false vim.o.wrap = false vim.o.clipboard = "unnamedplus" vim.opt.cmdheight = 1 vim.opt.laststatus = 3 -- Persistent undos vim.opt.undofile = true vim.filetype.add({ extension = { service = "systemd", templ = "templ" }, pattern = { [".*/%.github/workflows/.*.yml"] = "yaml.github", [".*/%.github/workflows/.*.yaml"] = "yaml.github", }, }) vim.opt.packpath:prepend(vim.fn.stdpath("data") .. "/site") vim.pack.add({ { src = github("mrcjkb/rustaceanvim"), version = vim.version.range("^9") }, github("Saecki/crates.nvim"), github("ziglang/zig.vim"), github("EdenEast/nightfox.nvim"), github("folke/which-key.nvim"), github("folke/snacks.nvim"), github("echasnovski/mini.icons"), github("folke/lsp-trouble.nvim"), github("stevearc/conform.nvim"), github("nvim-lualine/lualine.nvim"), github("nvim-treesitter/nvim-treesitter"), github("nvim-treesitter/nvim-treesitter-context"), }, { confirm = false, load = true }) local nts = require("nvim-treesitter") local ts_parsers = { "astro", "bash", "c", "dockerfile", "gitcommit", "go", "gomod", "lua", "python", "query", "rust", "toml", "yaml", "just", } local installed_parsers = nts.get_installed("parsers") local missing_parsers = vim.tbl_filter(function(parser) return not vim.list_contains(installed_parsers, parser) end, ts_parsers) if #missing_parsers > 0 then nts.install(missing_parsers) end vim.api.nvim_create_autocmd("PackChanged", { callback = function(event) if event.data.spec.name == "nvim-treesitter" and (event.data.kind == "install" or event.data.kind == "update") then nts.update() end end, }) vim.api.nvim_create_autocmd("FileType", { pattern = ts_parsers, callback = function() pcall(vim.treesitter.start) end, }) require("snacks").setup({ input = {}, picker = { sources = { files = { hidden = true, exclude = { "*.lock", ".env*" }, }, grep = { hidden = true, exclude = { "*.lock", ".env*" }, }, }, }, indent = { animate = { enabled = false, }, }, explorer = {}, notifier = {}, }) require("mini.icons").setup() require("trouble").setup() vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, { pattern = "Cargo.toml", once = true, callback = function() require("crates").setup({ lsp = { enabled = true, actions = true, completion = true, hover = true, }, }) end, }) vim.api.nvim_create_autocmd("BufReadPost", { callback = function(args) local mark = vim.api.nvim_buf_get_mark(args.buf, '"') local line_count = vim.api.nvim_buf_line_count(args.buf) if mark[1] > 0 and mark[1] <= line_count then vim.api.nvim_win_set_cursor(0, mark) -- defer centering slightly so it's applied after render vim.schedule(function() vim.cmd("normal! zz") end) end end, }) require("which-key").setup() require("lualine").setup({ options = { component_separators = { left = "|", right = "|" }, section_separators = "", }, }) vim.cmd.colorscheme("carbonfox") local conform_folder = "/Users/ethan/Documents/work/openfe/openfe" local cwd = vim.fs.normalize(vim.loop.cwd() or "") conform_folder = vim.fs.normalize(conform_folder) if cwd:sub(1, #conform_folder) ~= conform_folder then require("conform").setup({ formatters_by_ft = { lua = { "stylua" }, python = { "ruff_format" }, terraform = { "tofu_fmt" }, astro = { "prettierd", "prettier", stop_after_first = true }, svelte = { "prettierd", "prettier", stop_after_first = true }, typescript = { "prettierd", "prettier", stop_after_first = true }, javascript = { "prettierd", "prettier", stop_after_first = true }, }, format_on_save = { timeout_ms = 500, lsp_fallback = true, }, }) end require("mappings") vim.cmd("set completeopt+=noselect") vim.lsp.enable({ "lua_ls", "gh_actions_ls", "gopls", "astro", "nixd", "zls", "ruff", "tflint", "just", "ty", "templ", "terraformls", "nil_ls", "ts_ls", "tombi", "yamlls", "harper_ls", }) vim.g.rustaceanvim = { server = { on_attach = function(client, _) client.server_capabilities.workspace.didChangeWatchedFiles = { dynamicRegistration = false, } end, default_settings = { ["rust-analyzer"] = { files = { watcherExclude = { "**/.direnv/**", }, excludeDirs = { ".direnv", ".github", }, }, cargo = { features = "all", }, }, }, }, } vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) if client ~= nil and client:supports_method("textDocument/completion") then vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) end end, }) vim.api.nvim_create_augroup("LspAttach_inlayhints", {}) vim.api.nvim_create_autocmd("LspAttach", { group = "LspAttach_inlayhints", callback = function(event) local client = vim.lsp.get_client_by_id(event.data.client_id) -- Enable for all clients except for lua_ls if client and client.name ~= "lua_ls" then vim.lsp.inlay_hint.enable(true) end end, }) vim.api.nvim_create_autocmd({ "FileType" }, { group = vim.api.nvim_create_augroup("edit_text", { clear = true }), pattern = { "gitcommit", "markdown", "txt" }, desc = "Enable spell checking and text wrapping for certain filetypes", callback = function() vim.opt_local.spell = true end, }) vim.opt.spell = false vim.diagnostic.config({ -- update_in_insert = false, virtual_text = true, virtual_lines = { current_line = true }, })