repos / dotfiles

my dotfiles

dotfiles / dot_config / nvim
Eric Bower  ·  2025-11-26

init.lua

  1--[[
  2  erock's minimal config
  3  ======================
  4
  5  design goals:
  6    - single file
  7    - use native nvim features (>= v0.12)
  8    - use default keybindings unless painful otherwise
  9    - use built-ins unless painful otherwise
 10    - use default colorschemes
 11    - plugins must be integral to workflow
 12]]
 13local vim = vim -- suppress lsp warnings
 14local o = vim.opt
 15o.tabstop = 2
 16o.shiftwidth = 2
 17o.softtabstop = 2
 18o.expandtab = true
 19o.wrap = false
 20o.autoread = true
 21o.list = true -- show trailing characters
 22o.signcolumn = "yes"
 23o.backspace = "indent,eol,start"
 24o.shell = "/bin/bash"
 25o.colorcolumn = "100"
 26o.completeopt = { "menuone", "noselect", "popup" }
 27o.wildmode = { "lastused", "full" }
 28o.pumheight = 15
 29o.laststatus = 0
 30o.winborder = "rounded"
 31o.undofile = true
 32o.ignorecase = true
 33o.smartcase = true
 34o.swapfile = false
 35o.foldmethod = "indent"
 36o.foldlevelstart = 99
 37local g = vim.g
 38g.mapleader = ","
 39g.maplocalleader = ","
 40
 41local opts = { silent = true }
 42local map = vim.keymap.set
 43map("t", "<Esc>", [[<C-\><C-n>]], opts) -- exit terminal mode
 44map("n", "Q", "<nop>", opts) -- disable "Q"
 45map("n", "<C-k>", "<cmd>wincmd k<cr>", opts) -- navigate splits
 46map("n", "<C-j>", "<cmd>wincmd j<cr>", opts)
 47map("n", "<C-h>", "<cmd>wincmd h<cr>", opts)
 48map("n", "<C-l>", "<cmd>wincmd l<cr>", opts)
 49map("n", "<leader>t", "<cmd>bd!<cr>", opts)
 50map("n", "<leader>f", "<cmd>term fish<cr>", opts)
 51map({ "n", "v" }, "<leader>u", "<cmd>GitLink<cr>", opts)
 52map("n", "<leader>e", vim.diagnostic.open_float, opts)
 53map("n", "<leader>y", function() -- copy relative filepath to clipboard
 54	vim.fn.setreg("+", vim.fn.expand("%"))
 55end)
 56map("n", "<leader>r", function() -- toggle lsp loclist
 57	local loclist_win = vim.fn.getloclist(0, { winid = 0 }).winid
 58	if loclist_win > 0 then
 59		vim.cmd("lclose")
 60	else
 61		vim.diagnostic.setloclist({ open = true })
 62	end
 63end, opts)
 64map("n", "<leader>q", function() -- toggle quickfix
 65	for _, win in ipairs(vim.fn.getwininfo()) do
 66		if win.quickfix == 1 then
 67			vim.cmd("cclose")
 68			return
 69		end
 70	end
 71	vim.cmd("copen")
 72end)
 73map("n", "<leader>d", ":DiffviewOpen ")
 74map("n", "<leader>a", "<cmd>lua MiniFiles.open()<cr>")
 75map("n", "<leader>s", "<cmd>Pick files<cr>")
 76map("n", "<leader>g", "<cmd>Pick grep_live<cr>")
 77map("n", "<leader>b", "<cmd>Pick buffers<cr>")
 78
 79local augroup = vim.api.nvim_create_augroup("erock.cfg", { clear = true })
 80local autocmd = vim.api.nvim_create_autocmd
 81autocmd("Filetype", { group = augroup, pattern = "make", command = "setlocal noexpandtab tabstop=4 shiftwidth=4" })
 82autocmd("BufEnter", { -- disable automatic newline comment continuation
 83	callback = function()
 84		o.formatoptions = vim.opt.formatoptions:remove({ "c", "r", "o" })
 85	end,
 86})
 87
 88local function setup_lsp()
 89	vim.lsp.enable({
 90		"gopls", -- os package mgr: gopls
 91		"lua_ls", -- os package mgr: lua-language-server
 92		"pyright", -- npm i -g pyright
 93		"ts_ls", -- npm i -g typescript typescript-language-server
 94		"zls", -- os package mgr: zls
 95	})
 96
 97	autocmd("LspAttach", {
 98		group = augroup,
 99		callback = function(ev)
100			local bufopts = { noremap = true, silent = true, buffer = ev.buf }
101			map("n", "grd", vim.lsp.buf.definition, bufopts)
102			map("i", "<C-k>", vim.lsp.completion.get, bufopts) -- open completion menu manually
103			local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
104			local methods = vim.lsp.protocol.Methods
105			if client:supports_method(methods.textDocument_completion) then
106				vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
107			end
108		end,
109	})
110end
111
112vim.pack.add({
113	"https://github.com/neovim/nvim-lspconfig",
114	"https://github.com/nvim-mini/mini.pick",
115	"https://github.com/karb94/neoscroll.nvim",
116	"https://github.com/linrongbin16/gitlinker.nvim",
117	"https://github.com/sindrets/diffview.nvim",
118	"https://github.com/tpope/vim-fugitive",
119	"https://github.com/NicolasGB/jj.nvim",
120	"https://github.com/nvim-mini/mini.files",
121})
122
123vim.cmd("colorscheme default")
124
125require("vim._extui").enable({}) -- https://github.com/neovim/neovim/pull/27855
126setup_lsp()
127require("neoscroll").setup({ duration_multiplier = 0.3 })
128require("gitlinker").setup()
129require("jj").setup()
130require("diffview").setup({ use_icons = false })
131require("mini.pick").setup()
132require("mini.files").setup()