repos / dotfiles

my dotfiles

dotfiles / dot_config / nvim
Eric Bower  ·  2026-01-20

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
 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>q", "<cmd>bd!<cr>", opts)
 50map("n", "<leader>t", "<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>f", 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", ":b ")
 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    "pyright", -- npm i -g pyright
 92    "tsgo", -- npm i -g @typescript/native-preview
 93    "zls", -- os package mgr: zls
 94  })
 95
 96  autocmd("LspAttach", {
 97    group = augroup,
 98    callback = function(ev)
 99      local bufopts = { noremap = true, silent = true, buffer = ev.buf }
100      map("n", "grd", vim.lsp.buf.definition, bufopts)
101      map("i", "<C-k>", vim.lsp.completion.get, bufopts) -- open completion menu manually
102      local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
103      local methods = vim.lsp.protocol.Methods
104      if client:supports_method(methods.textDocument_completion) then
105        vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
106      end
107    end,
108  })
109end
110
111vim.pack.add({
112  "https://github.com/neovim/nvim-lspconfig",
113  "https://github.com/nvim-mini/mini.pick",
114  "https://github.com/karb94/neoscroll.nvim",
115  "https://github.com/linrongbin16/gitlinker.nvim",
116  "https://github.com/sindrets/diffview.nvim",
117  "https://github.com/tpope/vim-fugitive",
118  "https://github.com/nvim-mini/mini.files",
119})
120
121vim.cmd("colorscheme default")
122
123require("vim._extui").enable({}) -- https://github.com/neovim/neovim/pull/27855
124setup_lsp()
125require("neoscroll").setup({ duration_multiplier = 0.3 })
126require("gitlinker").setup()
127require("diffview").setup({ use_icons = false })
128require("mini.pick").setup()
129require("mini.files").setup()