diff --git a/init.lua b/init.lua index 51581a67..e7b99b6c 100644 --- a/init.lua +++ b/init.lua @@ -215,6 +215,11 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { 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', 'Qa', 'qa', { desc = '[Q]uit [A]ll windows' }) +vim.keymap.set('n', 'Qq', 'qa!', { desc = '[Q]uit all without saving (force)' }) +vim.keymap.set('n', 'Qw', 'wqa', { 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", "", "H", { desc = "Move window to the left" }) -- vim.keymap.set("n", "", "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' diff --git a/lazy-lock.json b/lazy-lock.json index 0ce93f8b..f268d32e 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -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" }, diff --git a/lua/custom/plugins/flutter.lua b/lua/custom/plugins/flutter.lua index b817d4ab..90a8e1ac 100644 --- a/lua/custom/plugins/flutter.lua +++ b/lua/custom/plugins/flutter.lua @@ -158,8 +158,7 @@ return { callback = function() local opts = { buffer = true, silent = true } - -- Flutter run/quit - vim.keymap.set('n', 'fr', 'FlutterRun', vim.tbl_extend('force', opts, { desc = '[F]lutter [R]un' })) + -- Flutter run/quit (instant, prompts for device) vim.keymap.set('n', 'fq', 'FlutterQuit', vim.tbl_extend('force', opts, { desc = '[F]lutter [Q]uit' })) vim.keymap.set('n', 'fR', 'FlutterRestart', vim.tbl_extend('force', opts, { desc = '[F]lutter Hot [R]estart' })) diff --git a/lua/custom/plugins/session.lua b/lua/custom/plugins/session.lua new file mode 100644 index 00000000..8cdd9f2a --- /dev/null +++ b/lua/custom/plugins/session.lua @@ -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: +-- ss - Save session manually +-- sr - Restore session manually +-- sd - Delete session for current directory +-- sf - Find/search all sessions (Telescope) +-- +-- Quit keymaps (in init.lua): +-- Qa - Quit all windows +-- Qq - Force quit all without saving +-- 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 + { + 'ss', + 'SessionSave', + desc = '[S]ession: [S]ave', + }, + { + 'sr', + 'SessionRestore', + desc = '[S]ession: [R]estore', + }, + { + 'sd', + 'SessionDelete', + desc = '[S]ession: [D]elete', + }, + { + 'sf', + 'SessionSearch', + desc = '[S]ession: [F]ind/search', + }, + }, + config = function(_, opts) + require('auto-session').setup(opts) + + -- Register with which-key + require('which-key').add { + { 's', group = '[S]ession' }, + { 'Q', group = '[Q]uit' }, + } + end, +} diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua index c7067891..14ff16e7 100644 --- a/lua/kickstart/plugins/neo-tree.lua +++ b/lua/kickstart/plugins/neo-tree.lua @@ -14,12 +14,56 @@ return { { '\\', ':Neotree reveal', 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 sf work the same in Neo-tree as in editor + ['sf'] = 'telescope_find', + ['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, + }, }, }