--[[ Centralized keymaps configuration This file contains all the keybindings for the Neovim configuration, organized by category for better readability and maintenance. Structure: 1. General keymaps (save, quit, etc.) 2. Navigation keymaps (windows, tabs, etc.) 3. UI keymaps (toggle elements, etc.) 4. Editing keymaps (formatting, etc.) 5. Plugin-specific keymaps ]] local M = {} -- Helper function for setting keymaps with proper labels local function map(mode, lhs, rhs, opts) opts = opts or {} opts.noremap = opts.noremap == nil and true or opts.noremap opts.silent = opts.silent == nil and true or opts.silent vim.keymap.set(mode, lhs, rhs, opts) end -- Initialize keymaps function M.setup() -------------------------------------------------- -- 1. GENERAL KEYMAPS -------------------------------------------------- -- Save and quit map('n', 'w', ':w', { desc = 'Save file' }) -- map('n', 'q', ':q', { desc = 'Quit' }) map('n', 'Q', ':qa!', { desc = 'Force quit all' }) map('n', 'W', ':wq', { desc = 'Save and quit' }) -- Common operations map('n', '/', 'nohlsearch', { desc = 'Clear search highlights' }) map('n', '', 'noh', { desc = 'Clear highlights' }) -------------------------------------------------- -- 2. NAVIGATION KEYMAPS -------------------------------------------------- -- Window navigation map('n', '', 'h', { desc = 'Move focus to the left window' }) map('n', '', 'j', { desc = 'Move focus to the down window' }) map('n', '', 'k', { desc = 'Move focus to the up window' }) map('n', '', 'l', { desc = 'Move focus to the right window' }) -- Window management map('n', '[', ':vsplit', { desc = 'Split window vertically' }) map('n', ']', ':split', { desc = 'Split window horizontally' }) map('n', 'wq', 'q', { desc = 'Close current window' }) map('n', 'wo', 'o', { desc = 'Close other windows' }) -- Window resizing map('n', '', ':resize +2', { desc = 'Increase window height' }) map('n', '', ':resize -2', { desc = 'Decrease window height' }) map('n', '', ':vertical resize -2', { desc = 'Decrease window width' }) map('n', '', ':vertical resize +2', { desc = 'Increase window width' }) -- Tab management (see also plugin-specific keymaps below) map('n', 'tn', ':tabnew', { desc = 'New tab' }) map('n', 'to', ':tabnew:Telescope find_files', { desc = 'New tab with file' }) map('n', 'tc', ':tabclose', { desc = 'Close tab' }) map('n', '', 'gt', { desc = 'Next tab' }) map('n', '', 'gT', { desc = 'Previous tab' }) -- Buffer navigation map('n', 'bb', "lua require('telescope.builtin').buffers()", { desc = 'Browse buffers' }) map('n', 'bd', ':bd', { desc = 'Delete buffer' }) map('n', 'bn', ':bn', { desc = 'Next buffer' }) map('n', 'bp', ':bp', { desc = 'Previous buffer' }) -------------------------------------------------- -- 3. UI KEYMAPS -------------------------------------------------- -- File explorer map('n', 'e', ':Explore', { desc = 'Open file explorer' }) -- Terminal map('n', 'tt', ':ToggleTerm', { desc = 'Toggle terminal' }) map('n', 'tf', ':ToggleTerm direction=float', { desc = 'Toggle floating terminal' }) map('n', 'th', ':ToggleTerm direction=horizontal', { desc = 'Toggle horizontal terminal' }) map('n', 'tv', ':ToggleTerm direction=vertical', { desc = 'Toggle vertical terminal' }) map('t', '', [[]], { desc = 'Exit terminal mode' }) -- Diagnostics map('n', 'xd', vim.diagnostic.open_float, { desc = 'Open diagnostic float' }) map('n', 'xl', vim.diagnostic.setloclist, { desc = 'Open diagnostic list' }) map('n', '[d', vim.diagnostic.goto_prev, { desc = 'Previous diagnostic' }) map('n', ']d', vim.diagnostic.goto_next, { desc = 'Next diagnostic' }) -------------------------------------------------- -- 4. EDITING KEYMAPS -------------------------------------------------- -- Move lines map('n', '', ':m .+1==', { desc = 'Move line down' }) map('n', '', ':m .-2==', { desc = 'Move line up' }) map('v', '', ":m '>+1gv=gv", { desc = 'Move selection down' }) map('v', '', ":m '<-2gv=gv", { desc = 'Move selection up' }) -- Better indenting map('v', '<', '', '>gv', { desc = 'Increase indent and reselect' }) return M end return M