feat: session management, qol keymaps

This commit is contained in:
Anup Sebastian 2025-10-30 07:31:43 -05:00
parent c8645eee5d
commit 503cd5c23b
5 changed files with 163 additions and 2 deletions

View File

@ -215,6 +215,11 @@ vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right win
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' })
-- Quit keymaps - easier ways to close Neovim (using capital Q to avoid conflict with diagnostic quickfix)
vim.keymap.set('n', '<leader>Qa', '<cmd>qa<CR>', { desc = '[Q]uit [A]ll windows' })
vim.keymap.set('n', '<leader>Qq', '<cmd>qa!<CR>', { desc = '[Q]uit all without saving (force)' })
vim.keymap.set('n', '<leader>Qw', '<cmd>wqa<CR>', { desc = '[Q]uit all and [W]rite (save)' })
-- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes
-- vim.keymap.set("n", "<C-S-h>", "<C-w>H", { desc = "Move window to the left" })
-- vim.keymap.set("n", "<C-S-l>", "<C-w>L", { desc = "Move window to the right" })
@ -235,6 +240,28 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end,
})
-- Ensure focus starts in the editor, not file tree
vim.api.nvim_create_autocmd('VimEnter', {
desc = 'Focus editor window on startup, not Neo-tree',
group = vim.api.nvim_create_augroup('kickstart-focus-editor', { clear = true }),
callback = function()
-- Wait a bit for plugins to load, then focus first non-special buffer
vim.defer_fn(function()
-- Find the first normal buffer window
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
local filetype = vim.api.nvim_buf_get_option(buf, 'filetype')
-- Skip special buffers like neo-tree, terminal, etc.
if buftype == '' and filetype ~= 'neo-tree' then
vim.api.nvim_set_current_win(win)
break
end
end
end, 50) -- 50ms delay to let plugins initialize
end,
})
-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'

View File

@ -1,5 +1,6 @@
{
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
"auto-session": { "branch": "main", "commit": "4cd20bb5c0138d1ce00ab35f8d7ac0f4fb4a403a" },
"blink.cmp": { "branch": "main", "commit": "327fff91fe6af358e990be7be1ec8b78037d2138" },
"conform.nvim": { "branch": "master", "commit": "9fd3d5e0b689ec1bf400c53cbbec72c6fdf24081" },
"copilot.vim": { "branch": "release", "commit": "da369d90cfd6c396b1d0ec259836a1c7222fb2ea" },

View File

@ -158,8 +158,7 @@ return {
callback = function()
local opts = { buffer = true, silent = true }
-- Flutter run/quit
vim.keymap.set('n', '<leader>fr', '<cmd>FlutterRun<cr>', vim.tbl_extend('force', opts, { desc = '[F]lutter [R]un' }))
-- Flutter run/quit (instant, prompts for device)
vim.keymap.set('n', '<leader>fq', '<cmd>FlutterQuit<cr>', vim.tbl_extend('force', opts, { desc = '[F]lutter [Q]uit' }))
vim.keymap.set('n', '<leader>fR', '<cmd>FlutterRestart<cr>', vim.tbl_extend('force', opts, { desc = '[F]lutter Hot [R]estart' }))

View File

@ -0,0 +1,90 @@
-- ========================================================================
-- SESSION MANAGEMENT - Auto-save and restore your workspace
-- ========================================================================
--
-- This plugin automatically saves your session (open files, window layout,
-- buffers, etc.) when you quit Neovim and restores it when you reopen
-- the same directory.
--
-- Features:
-- - Auto-saves session on exit
-- - Auto-restores session when opening Neovim in a directory
-- - Saves per-directory (each project has its own session)
-- - Saves open buffers, window splits, cursor positions, and more
--
-- Keymaps:
-- <leader>ss - Save session manually
-- <leader>sr - Restore session manually
-- <leader>sd - Delete session for current directory
-- <leader>sf - Find/search all sessions (Telescope)
--
-- Quit keymaps (in init.lua):
-- <leader>Qa - Quit all windows
-- <leader>Qq - Force quit all without saving
-- <leader>Qw - Save all and quit
--
-- Sessions are saved in: ~/.local/share/nvim/sessions/
-- ========================================================================
return {
'rmagatti/auto-session',
lazy = false, -- Load on startup to restore session
opts = {
-- Session save/restore options
auto_session_enabled = true, -- Automatically save sessions
auto_restore_enabled = true, -- Automatically restore sessions
auto_save_enabled = true, -- Auto-save on exit
auto_session_suppress_dirs = { '~/', '~/Downloads', '/' }, -- Don't save sessions in these dirs
auto_session_use_git_branch = false, -- One session per directory (not per git branch)
-- What to save in the session
auto_session_enable_last_session = false, -- Don't restore last session if not in a project
-- Hooks to run before/after session save/restore
pre_save_cmds = {
'Neotree close', -- Close Neo-tree before saving session
},
post_restore_cmds = {
-- You can add commands to run after restore here
},
-- Session lens (Telescope integration for browsing sessions)
session_lens = {
load_on_setup = true,
theme_conf = { border = true },
previewer = false,
},
},
keys = {
-- Manual session control
{
'<leader>ss',
'<cmd>SessionSave<cr>',
desc = '[S]ession: [S]ave',
},
{
'<leader>sr',
'<cmd>SessionRestore<cr>',
desc = '[S]ession: [R]estore',
},
{
'<leader>sd',
'<cmd>SessionDelete<cr>',
desc = '[S]ession: [D]elete',
},
{
'<leader>sf',
'<cmd>SessionSearch<cr>',
desc = '[S]ession: [F]ind/search',
},
},
config = function(_, opts)
require('auto-session').setup(opts)
-- Register with which-key
require('which-key').add {
{ '<leader>s', group = '[S]ession' },
{ '<leader>Q', group = '[Q]uit' },
}
end,
}

View File

@ -14,12 +14,56 @@ return {
{ '\\', ':Neotree reveal<CR>', desc = 'NeoTree reveal', silent = true },
},
opts = {
-- Don't open Neo-tree on startup, only when toggled
close_if_last_window = true, -- Close Neo-tree if it's the last window
popup_border_style = 'rounded',
enable_git_status = true,
enable_diagnostics = true,
-- Default to filesystem view
default_component_configs = {
indent = {
padding = 0,
},
},
filesystem = {
-- Follow the current file in the tree
follow_current_file = {
enabled = true,
leave_dirs_open = false,
},
-- Use system commands for file operations
use_libuv_file_watcher = true,
window = {
position = 'left',
width = 30,
mappings = {
['\\'] = 'close_window',
-- Make <leader>sf work the same in Neo-tree as in editor
['<leader>sf'] = 'telescope_find',
['<leader>sg'] = 'telescope_grep',
},
},
},
-- Add custom commands for Telescope integration
commands = {
telescope_find = function(state)
local node = state.tree:get_node()
local path = node:get_id()
require('telescope.builtin').find_files {
cwd = vim.fn.isdirectory(path) == 1 and path or vim.fn.fnamemodify(path, ':h'),
}
end,
telescope_grep = function(state)
local node = state.tree:get_node()
local path = node:get_id()
require('telescope.builtin').live_grep {
cwd = vim.fn.isdirectory(path) == 1 and path or vim.fn.fnamemodify(path, ':h'),
}
end,
},
},
}