-- Plugin-free fallback for https://www.mfserna.dev/nvim -- Same options and keymaps as init.lua, no network, no git, no build tools. -- Install: curl -fsSL https://www.mfserna.dev/nvim/install.sh | sh -s -- --minimal vim.g.mapleader = " " -- Options vim.opt.number = true vim.opt.relativenumber = true vim.opt.spell = false vim.opt.termguicolors = true vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.softtabstop = 4 vim.opt.expandtab = true vim.opt.foldmethod = "indent" vim.opt.foldenable = true vim.opt.foldlevel = 99 vim.opt.foldlevelstart = 99 vim.opt.updatetime = 250 vim.opt.signcolumn = "yes" vim.opt.cursorline = true vim.opt.scrolloff = 8 vim.opt.sidescrolloff = 8 vim.opt.splitright = true vim.opt.splitbelow = true vim.opt.ignorecase = true vim.opt.smartcase = true vim.opt.clipboard = "unnamedplus" vim.opt.undofile = true vim.opt.mouse = "a" vim.opt.showmode = false vim.opt.path:append("**") vim.opt.wildmenu = true vim.opt.wildignore:append({ "*/node_modules/*", "*/.git/*", "*/target/*", "*/build/*" }) if vim.fn.executable("rg") == 1 then vim.opt.grepprg = "rg --vimgrep --smart-case --hidden --glob '!.git'" vim.opt.grepformat = "%f:%l:%c:%m" end vim.cmd("syntax on") vim.filetype.add({ extension = { baml = "baml" } }) -- Built-in gruvbox-flavoured theme (0.10+), then the 0.8+ fallback. if not pcall(vim.cmd.colorscheme, "retrobox") then pcall(vim.cmd.colorscheme, "habamax") end local function apply_custom_highlights() vim.api.nvim_set_hl(0, "Comment", { fg = "#3d995d", italic = true }) vim.api.nvim_set_hl(0, "@comment", { link = "Comment" }) vim.api.nvim_set_hl(0, "@keyword", { fg = "#FF8700", bold = true }) vim.api.nvim_set_hl(0, "@string", { fg = "#D7AF87" }) end apply_custom_highlights() vim.api.nvim_create_autocmd("ColorScheme", { callback = apply_custom_highlights }) -- Diagnostics vim.diagnostic.config({ virtual_text = false, underline = true, update_in_insert = false, severity_sort = true, }) vim.api.nvim_create_autocmd("CursorHold", { callback = function() vim.diagnostic.open_float({ focusable = false, border = "rounded", source = true }) end, }) -- Auto-clear search highlight once the cursor leaves a match vim.api.nvim_create_autocmd("CursorMoved", { group = vim.api.nvim_create_augroup("auto_hlsearch", { clear = true }), callback = function() if vim.v.hlsearch == 1 and vim.fn.searchcount().exact_match == 0 then vim.schedule(function() vim.cmd.nohlsearch() end) end end, }) -- LSP: enable any server whose binary is already on PATH (Neovim 0.11+ API). local servers = { clangd = { cmd = { "clangd", "--background-index", "--clang-tidy" }, filetypes = { "c", "cpp", "objc", "objcpp", "cuda" }, root_markers = { "compile_commands.json", ".clangd", ".git" } }, pyright = { cmd = { "pyright-langserver", "--stdio" }, filetypes = { "python" }, root_markers = { "pyproject.toml", "setup.py", "requirements.txt", ".git" } }, rust_analyzer = { cmd = { "rust-analyzer" }, filetypes = { "rust" }, root_markers = { "Cargo.toml", ".git" } }, gopls = { cmd = { "gopls" }, filetypes = { "go", "gomod", "gowork", "gotmpl" }, root_markers = { "go.work", "go.mod", ".git" } }, lua_ls = { cmd = { "lua-language-server" }, filetypes = { "lua" }, root_markers = { ".luarc.json", ".git" }, settings = { Lua = { diagnostics = { globals = { "vim" } } } } }, ts_ls = { cmd = { "typescript-language-server", "--stdio" }, filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }, root_markers = { "tsconfig.json", "package.json", ".git" } }, baml = { cmd = { "baml", "lsp" }, filetypes = { "baml" }, root_markers = { "baml.toml", "baml_src" } }, } if vim.lsp.config and vim.lsp.enable then for name, config in pairs(servers) do if vim.fn.executable(config.cmd[1]) == 1 then vim.lsp.config(name, config) vim.lsp.enable(name) end end end vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local buf = ev.buf local client = vim.lsp.get_client_by_id(ev.data.client_id) if client and vim.lsp.completion and client:supports_method("textDocument/completion") then vim.lsp.completion.enable(true, client.id, buf, { autotrigger = true }) end local function bmap(mode, l, r, desc) vim.keymap.set(mode, l, r, { buffer = buf, desc = desc }) end bmap("n", "gd", vim.lsp.buf.definition, "Go to definition") bmap("n", "gD", vim.lsp.buf.declaration, "Go to declaration") bmap("n", "gi", vim.lsp.buf.implementation, "Go to implementation") bmap("n", "gr", vim.lsp.buf.references, "Find references") bmap("n", "K", vim.lsp.buf.hover, "Hover docs") bmap("n", "lk", vim.lsp.buf.signature_help, "Signature help") bmap("i", "", vim.lsp.buf.signature_help, "Signature help") bmap("n", "lr", vim.lsp.buf.rename, "Rename symbol") bmap("n", "la", vim.lsp.buf.code_action, "Code action") bmap("n", "lf", function() vim.lsp.buf.format({ async = true }) end, "Format buffer") bmap("n", "ls", vim.lsp.buf.document_symbol, "Document symbols") bmap("n", "lw", vim.lsp.buf.workspace_symbol, "Workspace symbols") end, }) -- Keybindings local map = vim.keymap.set -- File tree (netrw) map("n", "e", "Lexplore 30", { desc = "Toggle file tree" }) map("n", "t", "Lexplore 30", { desc = "Toggle file tree" }) -- Diagnostics map("n", "[d", vim.diagnostic.goto_prev, { desc = "Prev diagnostic" }) map("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" }) map("n", "q", vim.diagnostic.setloclist, { desc = "Diagnostics to loclist" }) -- Find (no telescope) map("n", "ff", ":find ", { desc = "Find files" }) map("n", "fg", ":silent grep! ", { desc = "Grep" }) map("n", "fb", "ls:b ", { desc = "Buffers" }) map("n", "fh", ":help ", { desc = "Help tags" }) map("n", "fr", "browse oldfiles", { desc = "Recent files" }) map("n", "fd", vim.diagnostic.setqflist, { desc = "Diagnostics" }) vim.api.nvim_create_autocmd("QuickFixCmdPost", { pattern = "grep", command = "cwindow" }) -- Buffers map("n", "", "bnext", { desc = "Next buffer" }) map("n", "", "bprevious", { desc = "Prev buffer" }) map("n", "x", "bdelete", { desc = "Close buffer" }) -- Terminal map({ "n", "t" }, [[]], function() local term = vim.iter(vim.api.nvim_list_wins()):find(function(win) return vim.bo[vim.api.nvim_win_get_buf(win)].buftype == "terminal" end) if term then vim.api.nvim_win_hide(term) else vim.cmd("botright 15split | terminal") vim.cmd.startinsert() end end, { desc = "Toggle terminal" }) map("n", "th", "botright 15split | terminal", { desc = "Terminal horizontal" }) map("n", "tv", "vsplit | terminal", { desc = "Terminal vertical" }) map("t", "", [[]], { desc = "Exit terminal mode" }) vim.api.nvim_create_autocmd("TermOpen", { callback = function() vim.opt_local.number = false vim.opt_local.relativenumber = false vim.opt_local.signcolumn = "no" end, }) -- Window navigation (works from editor, netrw, and terminal) map("n", "", "h", { desc = "Focus window left" }) map("n", "", "j", { desc = "Focus window down" }) map("n", "", "k", { desc = "Focus window up" }) map("n", "", "l", { desc = "Focus window right" }) map("t", "", [[h]], { desc = "Focus window left" }) map("t", "", [[j]], { desc = "Focus window down" }) map("t", "", [[k]], { desc = "Focus window up" }) map("t", "", [[l]], { desc = "Focus window right" }) -- Comment toggle: built-in gc/gcc since 0.10, nothing to configure.