clean config

This commit is contained in:
Harivansh Rathi 2026-02-20 22:34:08 -05:00
parent 1db6db7f92
commit 25aded9685
19 changed files with 468 additions and 852 deletions

View file

@ -1,38 +1,31 @@
-- Autocommands
local api = vim.api
local augroup = api.nvim_create_augroup("UserAutocmds", { clear = true })
local augroup = api.nvim_create_augroup('UserAutocmds', { clear = true })
-- Highlight on yank
api.nvim_create_autocmd("TextYankPost", {
group = augroup,
callback = function()
vim.highlight.on_yank({ higroup = "Visual", timeout = 200 })
end,
desc = "Highlight text on yank",
api.nvim_create_autocmd('TextYankPost', {
group = augroup,
callback = function()
vim.highlight.on_yank({ higroup = 'Visual', timeout = 200 })
end,
})
-- Restore cursor position on file open
api.nvim_create_autocmd("BufReadPost", {
group = augroup,
callback = function()
local excluded = { gitcommit = true, gitrebase = true }
if excluded[vim.bo.filetype] then return end
local mark = api.nvim_buf_get_mark(0, '"')
local line_count = api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= line_count then
pcall(api.nvim_win_set_cursor, 0, mark)
end
end,
desc = "Restore cursor position",
api.nvim_create_autocmd('BufReadPost', {
group = augroup,
callback = function()
if ({ gitcommit = true, gitrebase = true })[vim.bo.filetype] then
return
end
local mark = api.nvim_buf_get_mark(0, '"')
if mark[1] > 0 and mark[1] <= api.nvim_buf_line_count(0) then
pcall(api.nvim_win_set_cursor, 0, mark)
end
end,
})
-- Auto-resize splits on VimResized
api.nvim_create_autocmd("VimResized", {
group = augroup,
callback = function()
local current_tab = vim.fn.tabpagenr()
vim.cmd("tabdo wincmd =")
vim.cmd("tabnext " .. current_tab)
end,
desc = "Auto-resize splits",
api.nvim_create_autocmd('VimResized', {
group = augroup,
callback = function()
local tab = vim.fn.tabpagenr()
vim.cmd('tabdo wincmd =')
vim.cmd('tabnext ' .. tab)
end,
})

View file

@ -1,29 +1,21 @@
-- Keymaps using global map() helper
map('n', '<leader>w', '<cmd>w<cr>')
map('n', '<leader>q', '<cmd>q<cr>')
map('n', '<C-g>', '<cmd>Git<cr><cmd>only<cr>')
-- File operations
map("n", "<leader>w", "<cmd>w<cr>", { desc = "Save file" })
map("n", "<leader>q", "<cmd>q<cr>", { desc = "Quit" })
map("n", "<C-g>", "<cmd>Git<cr><cmd>only<cr>", { desc = "Git status (fullscreen)" })
map('n', '<Tab>', '<cmd>bnext<cr>')
map('n', '<S-Tab>', '<cmd>bprev<cr>')
map('n', '<leader>x', '<cmd>bdelete<cr>')
map('n', '<leader>b', '<cmd>enew<cr>')
-- Buffer navigation
map("n", "<Tab>", "<cmd>bnext<cr>", { desc = "Next buffer" })
map("n", "<S-Tab>", "<cmd>bprev<cr>", { desc = "Previous buffer" })
map("n", "<leader>x", "<cmd>bdelete<cr>", { desc = "Close buffer" })
map("n", "<leader>b", "<cmd>enew<cr>", { desc = "New buffer" })
map('n', '<C-h>', '<C-w>h')
map('n', '<C-j>', '<C-w>j')
map('n', '<C-k>', '<C-w>k')
map('n', '<C-l>', '<C-w>l')
-- Window navigation
map("n", "<C-h>", "<C-w>h", { desc = "Move to left window" })
map("n", "<C-j>", "<C-w>j", { desc = "Move to lower window" })
map("n", "<C-k>", "<C-w>k", { desc = "Move to upper window" })
map("n", "<C-l>", "<C-w>l", { desc = "Move to right window" })
map('n', 'J', 'mzJ`z')
map('x', 'x', '"_x')
map('x', 'p', '"_dP')
map('n', '<Esc>', '<cmd>nohlsearch<cr>')
map('n', '<leader>t', '<cmd>setlocal wrap!<cr>')
-- Better defaults
map("n", "J", "mzJ`z", { desc = "Join lines keeping cursor position" })
map("x", "x", '"_x', { desc = "Delete char without yanking" })
map("x", "p", '"_dP', { desc = "Paste without yanking replaced text" })
map("n", "<Esc>", "<cmd>nohlsearch<cr>", { desc = "Clear search highlight" })
map("n", "<leader>t", "<cmd>setlocal wrap!<cr>", { desc = "Toggle word wrap" })
-- Terminal
map("t", "<Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" })
map('t', '<Esc>', '<C-\\><C-n>')

View file

@ -1,52 +1,42 @@
-- Vim options
local o, opt = vim.o, vim.opt
-- Line numbers
o.number = true
o.relativenumber = true
-- Indentation
o.tabstop = 2
o.shiftwidth = 2
o.expandtab = true
o.smartindent = true
o.breakindent = true
-- Search
o.ignorecase = true
o.smartcase = true
o.hlsearch = false
o.incsearch = true
-- UI
o.termguicolors = true
o.cursorline = false
o.scrolloff = 8
o.signcolumn = "yes:2"
o.signcolumn = 'yes'
o.wrap = false
o.showmode = false
o.laststatus = 3
o.cmdheight = 0
opt.fillchars = { vert = "", fold = "", foldsep = "", diff = "" }
opt.shortmess:append("S")
opt.fillchars = { vert = '|', fold = '-', foldsep = '|', diff = '-' }
opt.shortmess:append('S')
-- Splits
o.splitbelow = true
o.splitright = true
-- Files
o.swapfile = false
o.backup = false
o.undofile = true
o.undodir = vim.fn.stdpath("data") .. "/undo"
o.undodir = vim.fn.stdpath('data') .. '/undo'
-- Folds (nvim-ufo)
o.foldlevel = 99
o.foldlevelstart = 99
o.foldenable = true
-- Misc
o.updatetime = 250
o.mouse = "a"
o.clipboard = "unnamedplus"
o.mouse = 'a'
o.clipboard = 'unnamedplus'