Compare commits

...

4 Commits

Author SHA256 Message Date
Wesley van Tilburg
7b9545f811 navigation: make sure to quit vim if oil is the only open buffer 2026-03-17 08:58:18 +00:00
Wesley van Tilburg
19b489e531 more navigation fixes (primarly disabling mouse when terminal is open) 2026-03-13 15:46:13 +00:00
Wesley van Tilburg
981cd0d732 chore: update Keybinds.md 2026-03-10 15:15:09 +00:00
Wesley van Tilburg
04e02b0620 fix: multiple navigation fixes for splits/popup terminal 2026-03-10 15:12:38 +00:00
6 changed files with 261 additions and 96 deletions

View File

@@ -1,28 +1,30 @@
# Neovim Keybinds & Commands Cheatsheet
## LSP (built-in, Neovim 0.11+)
## LSP
| Key | Action |
|-----|--------|
| `grn` | Rename symbol |
| `grr` | Go to references |
| `gra` | Code action |
| `gri` | Go to implementation |
| `gO` | Document symbols |
| `gd` | Go to definition |
| `gd` | Go to definition (reuses existing split) |
| `gD` | Go to declaration |
| `gi` | Go to implementation |
| `gr` | Go to references |
| `gt` | Go to type definition |
| `K` | Hover documentation |
| `<C-s>` (insert) | Signature help |
| `<C-k>` | Signature help (normal + insert) |
| `<leader>ca` | Code action |
| `<leader>rn` | Rename symbol |
| `<leader>f` | Format file |
## Diagnostics (built-in)
## Diagnostics
| Key / Command | Action |
|---------------|--------|
| Key | Action |
|-----|--------|
| `[d` | Previous diagnostic |
| `]d` | Next diagnostic |
| `<C-w>d` | Open diagnostic float |
| `:lua vim.diagnostic.setqflist()` | All diagnostics to quickfix |
| `:lua vim.diagnostic.setloclist()` | Buffer diagnostics to loclist |
| `gl` | Open diagnostic float |
| `<leader>q` | Buffer diagnostics to loclist |
Go files auto-format and organize imports on save.
## Autocompletion (blink.cmp)
@@ -38,29 +40,58 @@
Sources: LSP, buffer words, file paths.
## Buffer Navigation
## Pane Navigation
| Key | Action |
|-----|--------|
| `<Tab>` | Next buffer |
| `<Shift-Tab>` | Previous buffer |
| `<leader>x` | Close current buffer |
| `<Alt-h>` | Move left (or prev terminal tab in popup) |
| `<Alt-l>` | Move right (or next terminal tab in popup) |
| `<Alt-j>` | Move down |
| `<Alt-k>` | Move up |
Each split window shows its own filename bar (winbar) at the top.
Navigation wraps around (left from leftmost goes to rightmost).
Alt+h/l switch terminal tabs when the popup terminal is open.
## Buffer Tabs (per-split)
| Key | Action |
|-----|--------|
| `<Tab>` | Next buffer in current split |
| `<Shift-Tab>` | Previous buffer in current split |
| `<leader>x` | Close current buffer |
| `:q` | Close current buffer (keeps split) |
| `:wq` | Save and close current buffer |
Each file belongs to one split only. Selecting an already-open file from oil focuses its split.
## File Explorer (oil.nvim)
| Key / Command | Action |
|---------------|--------|
| `<leader>e` | Toggle file tree (left sidebar) |
| `-` or `<BS>` | Go up one directory (in file tree) |
| `<CR>` | Open file in last used code window (auto-focuses there) |
| `-` or `<BS>` | Go up one directory |
| `<CR>` | Open file in last used code split |
| `<leader>d` | Delete file/directory under cursor |
| `g.` | Toggle hidden files |
| `<C-p>` | Preview file |
| `<C-c>` | Close oil |
| `:w` (in oil buffer) | Save filesystem changes (renames, deletes, etc.) |
| `:w` (in oil buffer) | Save filesystem changes (renames, moves, etc.) |
Edit filenames directly in the buffer, then `:w` to apply.
File tree opens automatically on startup. Edit filenames directly in the buffer, then `:w` to apply.
## Popup Terminal
| Key | Action |
|-----|--------|
| `<C-t>` | Toggle popup terminal |
| `<Alt-h>` | Previous terminal tab |
| `<Alt-l>` | Next terminal tab |
| `<C-n>` | New terminal tab |
| `<C-w>` | Close terminal tab |
| `<C-v>` | Paste from clipboard |
| `<Esc>` | Exit to normal mode |
Terminal session persists when hidden. Tab indicator in title: `Terminal [1] 2 3`.
## Task Runner (overseer.nvim)
@@ -74,7 +105,7 @@ Edit filenames directly in the buffer, then `:w` to apply.
| `:OverseerTaskAction` | Pick a task, then an action |
| `:OverseerClearCache` | Clear cached tasks |
Tasks integrate with quickfix: errors from tasks populate the quickfix list.
Tasks integrate with quickfix: errors populate the quickfix list.
## Mason (LSP server management)
@@ -84,10 +115,15 @@ Tasks integrate with quickfix: errors from tasks populate the quickfix list.
| `:MasonInstall <server>` | Install a server |
| `:MasonUninstall <server>` | Remove a server |
| `:MasonUpdate` | Update all servers |
| `:MasonLog` | View install logs |
Auto-installed servers: `gopls`, `bashls`, `ansiblels`, `yamlls`.
## Plugins
| Command | Action |
|---------|--------|
| `:lua vim.pack.update()` | Update all plugins |
## Treesitter
| Command | Action |
@@ -106,35 +142,21 @@ Syntax highlighting is automatic once a parser is installed.
| `:cclose` | Close quickfix window |
| `:cnext` / `]q` | Next quickfix item |
| `:cprev` / `[q` | Previous quickfix item |
| `:cfirst` | First item |
| `:clast` | Last item |
## Window Resizing (built-in)
## Window Management
| Key | Action |
|-----|--------|
| `<C-w>>` | Wider (right) |
| `<C-w><` | Narrower (left) |
| `<C-w>v` | Vertical split |
| `<C-w>s` | Horizontal split |
| `<C-w>>` | Wider |
| `<C-w><` | Narrower |
| `<C-w>+` | Taller |
| `<C-w>-` | Shorter |
| `<C-w>=` | Equal size all |
| `10<C-w>>` | Wider by 10 columns |
## General (built-in)
| Key | Action |
|-----|--------|
| `<C-w>s` | Split horizontal |
| `<C-w>v` | Split vertical |
| `<C-t>` | Toggle floating popup terminal |
| `<Alt-h/j/k/l>` | Move between panes (also works from terminal) |
| `<C-w>h/j/k/l` | Move between panes (default) |
| `:e <path>` | Open file |
| `u` | Undo |
| `<C-r>` | Redo |
| `.` | Repeat last change |
| `*` | Search word under cursor |
| `:noh` | Clear search highlight |
Splitting from oil auto-redirects to the code area.
## Sessions / Layout
@@ -143,7 +165,7 @@ Syntax highlighting is automatic once a parser is installed.
| `<leader>ss` | Save current layout/session |
| `<leader>sl` | Load saved layout/session |
Saves window positions, sizes, buffers, and current directory.
Saves window positions, sizes, buffers, terminals, and current directory.
## Statusline

View File

@@ -6,8 +6,37 @@ vim.api.nvim_create_autocmd("TextYankPost", {
end,
})
-- Buffer tab navigation (scoped to current window)
local function cycle_win_buf(dir)
-- Quit Neovim if only oil windows remain (skip during startup)
_G._nvim_ready = false
vim.api.nvim_create_autocmd("VimEnter", {
group = vim.api.nvim_create_augroup("nvim_ready_flag", { clear = true }),
callback = function()
vim.schedule(function() _G._nvim_ready = true end)
end,
})
function _G.quit_if_only_oil()
vim.schedule(function()
if not _G._nvim_ready then return end
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_get_config(win).relative == "" then
local buf = vim.api.nvim_win_get_buf(win)
local ft = vim.bo[buf].filetype
local name = vim.api.nvim_buf_get_name(buf)
if ft ~= "oil" and name ~= "" then
return
end
if ft ~= "oil" and name == "" and vim.bo[buf].modified then
return
end
end
end
vim.cmd("qa")
end)
end
-- Buffer tab navigation (per-window, exclusive)
local function cycle_buf(dir)
local bufs = _G.get_win_bufs()
if #bufs <= 1 then return end
local current = vim.api.nvim_get_current_buf()
@@ -18,13 +47,13 @@ local function cycle_win_buf(dir)
return
end
end
if #bufs > 0 then vim.api.nvim_set_current_buf(bufs[1]) end
end
vim.keymap.set("n", "<Tab>", function() cycle_win_buf(1) end, { desc = "Next buffer tab" })
vim.keymap.set("n", "<S-Tab>", function() cycle_win_buf(-1) end, { desc = "Previous buffer tab" })
vim.keymap.set("n", "<Tab>", function() cycle_buf(1) end, { desc = "Next buffer tab" })
vim.keymap.set("n", "<S-Tab>", function() cycle_buf(-1) end, { desc = "Previous buffer tab" })
vim.keymap.set("n", "<leader>x", function()
local bufs = _G.get_win_bufs()
local current = vim.api.nvim_get_current_buf()
-- Switch to another buffer in this window, or create a blank one
local switched = false
for _, buf in ipairs(bufs) do
if buf ~= current then
@@ -38,32 +67,50 @@ vim.keymap.set("n", "<leader>x", function()
vim.bo.bufhidden = "wipe"
end
vim.cmd("bdelete " .. current)
_G.quit_if_only_oil()
end, { desc = "Close buffer tab" })
-- Splits duplicate current file (default Vim behavior)
vim.keymap.set("n", "<C-w>v", ":vsplit<CR>", { desc = "Vertical split" })
vim.keymap.set("n", "<C-w>s", ":split<CR>", { desc = "Horizontal split" })
-- Also check when a window is closed (e.g. :q)
vim.api.nvim_create_autocmd("WinClosed", {
group = vim.api.nvim_create_augroup("quit_if_only_oil_winclose", { clear = true }),
callback = function() _G.quit_if_only_oil() end,
})
-- Move between panes with Alt+h/l, wraps around (works in normal and terminal mode)
local function wrap_move(dir)
local cur = vim.api.nvim_get_current_win()
vim.cmd("wincmd " .. dir)
if vim.api.nvim_get_current_win() == cur then
-- Didn't move, wrap around
local opposite = ({ h = "l", l = "h", j = "k", k = "j" })[dir]
-- Go to the far opposite end
vim.cmd("99wincmd " .. opposite)
end
end
vim.keymap.set("n", "<A-h>", function() wrap_move("h") end, { desc = "Move to left pane (wrap)" })
vim.keymap.set("n", "<A-l>", function() wrap_move("l") end, { desc = "Move to right pane (wrap)" })
vim.keymap.set("n", "<A-j>", function() wrap_move("j") end, { desc = "Move to pane below (wrap)" })
vim.keymap.set("n", "<A-k>", function() wrap_move("k") end, { desc = "Move to pane above (wrap)" })
vim.keymap.set("t", "<A-h>", function() vim.cmd("stopinsert") wrap_move("h") end, { desc = "Move to left pane (wrap)" })
vim.keymap.set("t", "<A-l>", function() vim.cmd("stopinsert") wrap_move("l") end, { desc = "Move to right pane (wrap)" })
vim.keymap.set("t", "<A-j>", function() vim.cmd("stopinsert") wrap_move("j") end, { desc = "Move to pane below (wrap)" })
vim.keymap.set("t", "<A-k>", function() vim.cmd("stopinsert") wrap_move("k") end, { desc = "Move to pane above (wrap)" })
-- Prevent splitting from oil — redirect to last code window
vim.api.nvim_create_autocmd("WinNew", {
group = vim.api.nvim_create_augroup("no_split_oil", { clear = true }),
callback = function()
-- Skip floating windows (like popup terminal)
local new_win = vim.api.nvim_get_current_win()
if vim.api.nvim_win_get_config(new_win).relative ~= "" then return end
local prev_win = vim.fn.win_getid(vim.fn.winnr("#"))
if not vim.api.nvim_win_is_valid(prev_win) then return end
local prev_buf = vim.api.nvim_win_get_buf(prev_win)
if vim.bo[prev_buf].filetype ~= "oil" then return end
-- A split was created from oil — close it and redo from code window
local new_buf = vim.api.nvim_get_current_buf()
vim.api.nvim_win_close(new_win, true)
local target = _G.last_code_win
if not target or not vim.api.nvim_win_is_valid(target) then
-- Find any non-oil window
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
local buf = vim.api.nvim_win_get_buf(win)
if vim.bo[buf].filetype ~= "oil" and vim.api.nvim_win_get_config(win).relative == "" then
target = win
break
end
end
end
if target and vim.api.nvim_win_is_valid(target) then
vim.api.nvim_set_current_win(target)
vim.cmd("vsplit")
end
end,
})
-- Floating popup terminal with tabs (toggle with <C-t>)
local popup_term = { bufs = {}, current = 1, win = nil }
@@ -164,16 +211,51 @@ local function close_term_tab()
end
end
-- Init first tab
ensure_term_buf(1)
vim.keymap.set("n", "<C-t>", toggle_popup_term, { desc = "Toggle popup terminal" })
vim.keymap.set("t", "<C-t>", toggle_popup_term, { desc = "Toggle popup terminal" })
vim.keymap.set("t", "<A-]>", function() switch_term(popup_term.current % #popup_term.bufs + 1) end, { desc = "Next terminal tab" })
vim.keymap.set("t", "<A-[>", function() switch_term((popup_term.current - 2) % #popup_term.bufs + 1) end, { desc = "Prev terminal tab" })
vim.keymap.set("t", "<C-n>", new_term_tab, { desc = "New terminal tab" })
vim.keymap.set("t", "<C-w>", close_term_tab, { desc = "Close terminal tab" })
-- Move between panes with Alt+h/l, wraps around (works in normal and terminal mode)
local function wrap_move(dir)
local cur = vim.api.nvim_get_current_win()
vim.cmd("wincmd " .. dir)
if vim.api.nvim_get_current_win() == cur then
local opposite = ({ h = "l", l = "h", j = "k", k = "j" })[dir]
vim.cmd("99wincmd " .. opposite)
end
end
vim.keymap.set("n", "<A-h>", function() wrap_move("h") end, { desc = "Move to left pane (wrap)" })
vim.keymap.set("n", "<A-l>", function() wrap_move("l") end, { desc = "Move to right pane (wrap)" })
vim.keymap.set("n", "<A-j>", function() wrap_move("j") end, { desc = "Move to pane below (wrap)" })
vim.keymap.set("n", "<A-k>", function() wrap_move("k") end, { desc = "Move to pane above (wrap)" })
-- Alt+h/l in terminal: only switch terminal tabs in popup, no pane navigation
vim.keymap.set("t", "<A-h>", function()
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then
switch_term((popup_term.current - 2) % #popup_term.bufs + 1)
end
end, { desc = "Prev term tab" })
vim.keymap.set("t", "<A-l>", function()
if popup_term.win and vim.api.nvim_win_is_valid(popup_term.win) then
switch_term(popup_term.current % #popup_term.bufs + 1)
end
end, { desc = "Next term tab" })
-- Block pane navigation in terminal mode
vim.keymap.set("t", "<A-j>", "<Nop>")
vim.keymap.set("t", "<A-k>", "<Nop>")
-- Disable mouse when terminal is focused, restore on leave
vim.api.nvim_create_autocmd("TermEnter", {
group = vim.api.nvim_create_augroup("term_no_mouse", { clear = true }),
callback = function() vim.o.mouse = "" end,
})
vim.api.nvim_create_autocmd("TermLeave", {
group = vim.api.nvim_create_augroup("term_restore_mouse", { clear = true }),
callback = function() vim.o.mouse = "a" end,
})
-- Terminal copy/paste
vim.keymap.set("t", "<C-v>", function()
local reg = vim.fn.getreg("+")
@@ -182,7 +264,17 @@ vim.keymap.set("t", "<C-v>", function()
end
end, { desc = "Paste from clipboard" })
vim.keymap.set("t", "<C-y>", [[<C-\><C-n>V]], { desc = "Select current line (normal mode)" })
vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]], { desc = "Exit to normal mode" })
-- Auto-enter insert mode when switching to a terminal window
-- Uses WinEnter only (not BufEnter) so :wq from nested editors (e.g. git commit) works
vim.api.nvim_create_autocmd("WinEnter", {
group = vim.api.nvim_create_augroup("term_auto_insert", { clear = true }),
callback = function()
if vim.bo.buftype == "terminal" and vim.fn.mode() ~= "t" then
vim.cmd.startinsert()
end
end,
})
-- Save/restore layout with :mksession
vim.opt.sessionoptions = "buffers,curdir,folds,winpos,winsize,terminal"

View File

@@ -28,24 +28,42 @@ opt.splitright = true
opt.equalalways = false
opt.cursorline = true
-- Per-window buffer tabs (winbar)
-- Track which buffers were opened in each window
-- 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" then return end
if not _G.win_bufs[win] then _G.win_bufs[win] = {} end
-- Remove if already tracked, then add to end
for i, b in ipairs(_G.win_bufs[win]) do
if b == buf then table.remove(_G.win_bufs[win], i) break end
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()
local win = vim.api.nvim_get_current_win()
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
@@ -57,13 +75,13 @@ function _G.get_win_bufs()
end
function _G.winbar_tabs()
local bufs = _G.get_win_bufs()
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")
if name == "" then name = "[No Name]" end
local mod = vim.bo[buf].modified and " +" or ""
if buf == current then
table.insert(parts, "%#TabLineSel# " .. name .. mod .. " %#WinBar#")
@@ -79,6 +97,15 @@ vim.api.nvim_create_autocmd("BufEnter", {
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)

View File

@@ -3,7 +3,7 @@ vim.pack.add({
"https://github.com/nvim-treesitter/nvim-treesitter",
"https://github.com/williamboman/mason.nvim",
"https://github.com/williamboman/mason-lspconfig.nvim",
{ src = "https://github.com/saghen/blink.cmp", version = vim.version.range("1.*") },
{ src = "https://github.com/saghen/blink.cmp", version = vim.version.range("1.*"), build = "cargo build --release" },
"https://github.com/stevearc/oil.nvim",
"https://github.com/stevearc/overseer.nvim",
})

View File

@@ -66,6 +66,22 @@ vim.api.nvim_create_autocmd("FileType", {
local dir = oil.get_current_dir()
if not dir then return end
local filepath = dir .. entry.name
local abs_path = vim.fn.fnamemodify(filepath, ":p")
-- Check if file is already tracked in any window's tab list
for win, bufs in pairs(_G.win_bufs or {}) do
if vim.api.nvim_win_is_valid(win) then
for _, buf in ipairs(bufs) do
if vim.api.nvim_buf_is_valid(buf)
and vim.fn.fnamemodify(vim.api.nvim_buf_get_name(buf), ":p") == abs_path then
vim.api.nvim_set_current_win(win)
vim.api.nvim_set_current_buf(buf)
return
end
end
end
end
local target_win = nil
-- Try last focused code window
@@ -92,7 +108,6 @@ vim.api.nvim_create_autocmd("FileType", {
if target_win then
vim.api.nvim_set_current_win(target_win)
-- Remember blank buffer to clean up after opening
local old_buf = vim.api.nvim_get_current_buf()
local is_blank = vim.api.nvim_buf_get_name(old_buf) == ""
and not vim.bo[old_buf].modified
@@ -100,7 +115,16 @@ vim.api.nvim_create_autocmd("FileType", {
and vim.api.nvim_buf_get_lines(old_buf, 0, 1, false)[1] == ""
vim.cmd.edit(vim.fn.fnameescape(filepath))
if is_blank and old_buf ~= vim.api.nvim_get_current_buf() then
vim.api.nvim_buf_delete(old_buf, { force = true })
local in_use = false
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_get_buf(win) == old_buf then
in_use = true
break
end
end
if not in_use then
vim.api.nvim_buf_delete(old_buf, { force = true })
end
end
else
-- No code window exists: create a split to the right

View File

@@ -1,7 +1,7 @@
{
"plugins": {
"blink.cmp": {
"rev": "e9556f9b981f395e22a6bfd69fd5f3008a2a6cd9",
"rev": "451168851e8e2466bc97ee3e026c3dcb9141ce07",
"src": "https://github.com/saghen/blink.cmp",
"version": "1.0.0 - 2.0.0"
},
@@ -10,7 +10,7 @@
"src": "https://github.com/rebelot/kanagawa.nvim"
},
"mason-lspconfig.nvim": {
"rev": "a324581a3c83fdacdb9804b79de1cbe00ce18550",
"rev": "a676ab7282da8d651e175118bcf54483ca11e46d",
"src": "https://github.com/williamboman/mason-lspconfig.nvim"
},
"mason.nvim": {
@@ -18,11 +18,11 @@
"src": "https://github.com/williamboman/mason.nvim"
},
"nvim-lspconfig": {
"rev": "2b87d107942b9eebef768512f5849330335a9493",
"rev": "dc2f86d2b66a6e01a98c37cdadd3be3e90f8ab9a",
"src": "https://github.com/neovim/nvim-lspconfig"
},
"nvim-treesitter": {
"rev": "1970f0d3bbb99c7659e58914948749437c7b7398",
"rev": "2cc172c28e5550e00e6beead4599b1469469c1c7",
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
},
"oil.nvim": {
@@ -30,7 +30,7 @@
"src": "https://github.com/stevearc/oil.nvim"
},
"overseer.nvim": {
"rev": "2802c15182dae2de71f9c82e918d7ba850b90c22",
"rev": "a2194447f4c5a1baf95139c5c7b539fa7b0d012f",
"src": "https://github.com/stevearc/overseer.nvim"
}
}