Finally modularize neovim configuration

This commit is contained in:
Alex Selimov 2025-09-03 09:05:52 -04:00
parent d4ca4668c4
commit e2697f61fd
No known key found for this signature in database
GPG key ID: BC03C17FF5CFFFD2
16 changed files with 872 additions and 1004 deletions

35
lua/config/autocmds.lua Normal file
View file

@ -0,0 +1,35 @@
-- Autocmds configuration
-- Disable semantic tokens
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
client.server_capabilities.semanticTokensProvider = nil
end,
})
-- Go back to last edited line when reopening file
vim.api.nvim_create_autocmd("BufRead", {
callback = function(opts)
vim.api.nvim_create_autocmd("BufWinEnter", {
once = true,
buffer = opts.buf,
callback = function()
local ft = vim.bo[opts.buf].filetype
local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
if
not (ft:match("gitcommit") and ft:match("gitrebase"))
and last_known_line > 1
and last_known_line <= vim.api.nvim_buf_line_count(opts.buf)
then
vim.api.nvim_feedkeys([[g`"]], "nx", false)
end
end,
})
end,
})
-- Disable semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end

34
lua/config/formatting.lua Normal file
View file

@ -0,0 +1,34 @@
-- Formatting configuration
-- Set rustfmt command
vim.g["rustfmt_command"] = "rustfmt +nightly"
-- Commands to disable/enable formatting
require("conform").setup({
format_on_save = function(bufnr)
-- Disable with a global or buffer-local variable
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_fallback = true }
end,
})
vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = "Disable autoformat-on-save",
bang = true,
})
vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})

19
lua/config/keymaps.lua Normal file
View file

@ -0,0 +1,19 @@
-- Keymaps configuration
-- Clear search highlight
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
-- Diagnostic keymaps
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous [D]iagnostic message" })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next [D]iagnostic message" })
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Show diagnostic [E]rror messages" })
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })
-- Window navigation
vim.keymap.set("n", "<C-h>", "<C-w><C-h>", { desc = "Move focus to the left window" })
vim.keymap.set("n", "<C-l>", "<C-w><C-l>", { desc = "Move focus to the right window" })
vim.keymap.set("n", "<C-j>", "<C-w><C-j>", { desc = "Move focus to the lower window" })
vim.keymap.set("n", "<C-k>", "<C-w><C-k>", { desc = "Move focus to the upper window" })
-- LSP keymaps
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Goto Definition" })

16
lua/config/lazy.lua Normal file
View file

@ -0,0 +1,16 @@
-- Lazy.nvim plugin manager setup
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
end
vim.opt.rtp:prepend(lazypath)
-- User dictionary for spell checking
local path = vim.fn.stdpath("config") .. "/spell/en.utf-8.add"
local words = {}
for word in io.open(path, "r"):lines() do
table.insert(words, word)
end

55
lua/config/options.lua Normal file
View file

@ -0,0 +1,55 @@
-- Options configuration
vim.g.mapleader = ";"
vim.g.maplocalleader = ";"
-- Line numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- Mouse
vim.opt.mouse = ""
-- Mode display
vim.opt.showmode = false
-- Search
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.hlsearch = true
-- Sign column
vim.opt.signcolumn = "yes"
-- Splits
vim.opt.splitright = true
vim.opt.splitbelow = true
-- Whitespace display
vim.opt.list = true
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "" }
-- Live substitution preview
vim.opt.inccommand = "split"
-- Cursor line
vim.opt.cursorline = true
-- General settings
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4
vim.opt.expandtab = true
vim.opt.tw = 100
vim.opt.colorcolumn = "+1"
vim.opt.termguicolors = true
vim.opt.pumheight = 5
-- Light mode check
local function file_exists(name)
local f = io.open(name, "r")
return f ~= nil and io.close(f)
end
local home = os.getenv("HOME")
if file_exists(home .. "/.config/nvim/light_mode") then
vim.opt.background = "light"
end