chore: update Keybinds.md more navigation fixes (primarly disabling mouse when terminal is open) rm session
126 lines
3.3 KiB
Lua
126 lines
3.3 KiB
Lua
local opt = vim.opt
|
|
|
|
-- Line numbers
|
|
opt.number = true
|
|
opt.relativenumber = false
|
|
|
|
-- Search
|
|
opt.ignorecase = true
|
|
opt.smartcase = true
|
|
opt.hlsearch = true
|
|
opt.incsearch = true
|
|
|
|
-- Tabs / indentation
|
|
opt.expandtab = true
|
|
opt.shiftwidth = 4
|
|
opt.tabstop = 4
|
|
opt.smartindent = true
|
|
|
|
-- Undo
|
|
opt.undofile = true
|
|
|
|
-- UI
|
|
opt.termguicolors = true
|
|
opt.signcolumn = "yes"
|
|
opt.scrolloff = 8
|
|
opt.splitbelow = true
|
|
opt.splitright = true
|
|
opt.equalalways = false
|
|
opt.cursorline = true
|
|
|
|
-- Per-window buffer tabs (exclusive: each file belongs to one split only)
|
|
_G.win_bufs = {}
|
|
|
|
-- Remove a buffer from all windows' tracking
|
|
function _G.untrack_buf_everywhere(buf)
|
|
for win, bufs in pairs(_G.win_bufs) do
|
|
for i, b in ipairs(bufs) do
|
|
if b == buf then
|
|
table.remove(bufs, i)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function _G.track_buf()
|
|
local win = vim.api.nvim_get_current_win()
|
|
local buf = vim.api.nvim_get_current_buf()
|
|
if not vim.bo[buf].buflisted
|
|
or vim.bo[buf].filetype == "oil"
|
|
or vim.bo[buf].buftype == "terminal"
|
|
or vim.api.nvim_buf_get_name(buf) == "" then
|
|
return
|
|
end
|
|
if not _G.win_bufs[win] then _G.win_bufs[win] = {} end
|
|
-- Already tracked in this window, skip
|
|
for _, b in ipairs(_G.win_bufs[win]) do
|
|
if b == buf then return end
|
|
end
|
|
-- Remove from any other window (exclusive ownership)
|
|
_G.untrack_buf_everywhere(buf)
|
|
table.insert(_G.win_bufs[win], buf)
|
|
end
|
|
|
|
function _G.get_win_bufs(win)
|
|
win = win or vim.api.nvim_get_current_win()
|
|
local bufs = {}
|
|
for _, buf in ipairs(_G.win_bufs[win] or {}) do
|
|
if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].buflisted then
|
|
table.insert(bufs, buf)
|
|
end
|
|
end
|
|
_G.win_bufs[win] = bufs
|
|
return bufs
|
|
end
|
|
|
|
function _G.winbar_tabs()
|
|
local win = vim.api.nvim_get_current_win()
|
|
local bufs = _G.get_win_bufs(win)
|
|
if #bufs == 0 then return "" end
|
|
local current = vim.api.nvim_get_current_buf()
|
|
local parts = {}
|
|
for _, buf in ipairs(bufs) do
|
|
local name = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(buf), ":t")
|
|
local mod = vim.bo[buf].modified and " +" or ""
|
|
if buf == current then
|
|
table.insert(parts, "%#TabLineSel# " .. name .. mod .. " %#WinBar#")
|
|
else
|
|
table.insert(parts, " " .. name .. mod .. " ")
|
|
end
|
|
end
|
|
return table.concat(parts, "|")
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd("BufEnter", {
|
|
group = vim.api.nvim_create_augroup("track_win_bufs", { clear = true }),
|
|
callback = function() _G.track_buf() end,
|
|
})
|
|
|
|
-- Clean up tracking when a window closes
|
|
vim.api.nvim_create_autocmd("WinClosed", {
|
|
group = vim.api.nvim_create_augroup("clean_win_bufs", { clear = true }),
|
|
callback = function(ev)
|
|
local win = tonumber(ev.match)
|
|
if win then _G.win_bufs[win] = nil end
|
|
end,
|
|
})
|
|
|
|
opt.winbar = "%{%v:lua.winbar_tabs()%}"
|
|
|
|
-- Clipboard (system)
|
|
opt.clipboard = "unnamedplus"
|
|
|
|
-- Statusline (with git branch)
|
|
function _G.git_branch()
|
|
local branch = vim.fn.system("git -C " .. vim.fn.shellescape(vim.fn.expand("%:p:h")) .. " branch --show-current 2>/dev/null")
|
|
branch = branch:gsub("%s+", "")
|
|
if branch == "" then return "" end
|
|
return " " .. branch .. " |"
|
|
end
|
|
opt.statusline = " %f %m%r%=%{v:lua.git_branch()} %l:%c %p%% "
|
|
|
|
-- Misc
|
|
opt.updatetime = 250
|
|
opt.mouse = "a"
|