Replace hardcoded reasonix/lazygit keymap blocks with a single
loop over config.commands. Adding a new tool (e.g. codex) now only
requires two lines in user config:
commands = { codex = 'codex' },
keymaps = { codex = { 'n', '<leader>cx' } },
Commands can be strings or functions for lazy evaluation.
When terminal occupies main window and user directly opens a file
(:e somefile) in that window, the window's buffer no longer matches
term.bufnr. Previously this caused the hide path to incorrectly swap
back original_bufnr, wiping the user's file. Now we detect mismatch,
clear winid/borrowed, and re-evaluate use_main — which will correctly
fall through to a split when a real file is present.
When Neovim is launched without a file (empty unnamed buffer),
QQdock now reuses the current window instead of creating a split.
Toggle hide swaps back to the original empty buffer.
Detection: buffer name is empty, buftype empty, not modified.
Cache tracks borrowed flag and original_bufnr for restore.
Root cause: toggleterm uses botright split (tabpage-level) and
find_open_windows() jumps to existing terminals across tabpages,
destroying window layouts. persist_size=false in Terminal opts was
never consumed by toggleterm's ui.get_size().
Changes:
- Replace toggleterm Terminal cache with own {bufnr, winid, job_id, cmd}
- Use rightbelow {size}split/vsplit (current-window-local)
- Three-path open: hide (close win), restore (assign buf to new split), create
- winfixwidth/winfixheight to protect terminal window size
- bufhidden=hide to keep process alive on window close
- <C-\><C-\> hide keymap on terminal buffers
- config.debug flag for layout diagnostics
- pcall toggleterm setup(persist_size=false) as safety net