-- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` -- Swap : and ; around vim.keymap.set({ 'n', 'v' }, ':', ';') vim.keymap.set({ 'n', 'v' }, ';', ':') -- Clear highlights on search when pressing in normal mode -- See `:help hlsearch` vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. -- -- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping -- or just use to exit terminal mode vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) -- Keybinds to make split navigation easier. -- Use CTRL+ to switch between windows -- -- See `:help wincmd` for a list of all window commands vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) vim.keymap.set('n', '', 'H', { desc = 'Move window to the left' }) vim.keymap.set('n', '', 'L', { desc = 'Move window to the right' }) vim.keymap.set('n', '', 'J', { desc = 'Move window to the lower' }) vim.keymap.set('n', '', 'K', { desc = 'Move window to the upper' }) -- Overriding CTRL mappings because some of them are stupid vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Git blame', { desc = 'Git blame' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Telescope lsp_document_symbols', { desc = 'Show symbols in current document' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Telescope lsp_workspace_symbols', { desc = 'Show symbols in workspace' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Telescope oldfiles', { desc = 'Show recently opened files' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('telescope.builtin').git_files() end, { desc = 'Find all files' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('telescope.builtin').find_files { show_untracked = true, no_ignore = true, hidden = true, } end, { desc = 'Find all files' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('telescope.builtin').live_grep { hidden = true, } end, { desc = 'Search within the whole project' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Telescope quickfix', { desc = 'Show quickfix list' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'Telescope quickfixhistory', { desc = 'Show quickfix history' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'CodeCompanionChat Toggle', { desc = 'Open AI Actions' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', 'CodeCompanionActions', { desc = 'Open AI Actions' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('snacks').scratch() end, { desc = 'Open scratchpad' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('snacks').scratch.select() end, { desc = 'Open scratchpad buffers' }) vim.keymap.set({ 'n', 'v', 'c', 'i' }, '', function() require('snacks').terminal.toggle() end, { desc = 'Open terminal' }) -- Editing helpers vim.keymap.set('i', '', 'o', { desc = 'Add line below' }) vim.keymap.set('i', '', 'O', { desc = 'Add line above' }) vim.keymap.set('i', 'jj', '', { desc = 'Exit insert mode' }) vim.keymap.set('i', 'jk', '', { desc = 'Exit insert mode' }) vim.keymap.set('i', 'kk', '', { desc = 'Exit insert mode' }) vim.keymap.set('i', '', 'ddi', { desc = 'Delete line' }) vim.keymap.set('i', ';', 'mzA;`za', { desc = 'Append a semicolon' }) vim.keymap.set('n', ';', 'mzA;`za', { desc = 'Append a semicolon' }) vim.keymap.set('n', '{', 'mzF[`a``%i`z', { desc = 'Indent an array' }) vim.keymap.set('n', '}', 'mzF[`a``%i`zvi[:s/,\\s*/,\\r/gvi[=`z:nohlsearch', { desc = 'Indent an array some other way?' }) -- Git mappings vim.keymap.set('n', 'gaf', 'Git add %', { desc = 'Git add current file' }) vim.keymap.set('n', 'gaa', 'Git add --all', { desc = 'Git add all unstaged changes' }) vim.keymap.set('n', 'gap', 'Git add --patch --all', { desc = 'Git add all unstaged changes interactively' }) vim.keymap.set('n', 'gb', 'Git blame', { desc = 'Git blame' }) vim.keymap.set('n', 'gcm', 'Git commit -v', { desc = 'Git commit' }) vim.keymap.set('n', 'gp', 'Git push', { desc = 'Git push' }) vim.keymap.set('n', 'gup', 'Git pull --rebase', { desc = 'Git pull --rebase' }) vim.keymap.set('n', 'gsb', 'Git status', { desc = 'Git status' }) vim.keymap.set('n', 'gd', 'Git diff', { desc = 'Git diff' }) vim.keymap.set('n', 'gdc', 'Git diff --cached', { desc = 'Git diff' }) vim.keymap.set('n', 'gl', 'Git log', { desc = 'Git log' }) vim.keymap.set('n', 'gun', 'Git reset -- %', { desc = 'Git unstage file' }) vim.keymap.set('n', 'gco', 'Git checkout', { desc = 'Git checkout' }) vim.keymap.set('n', 'G', 'Git', { desc = 'Git' }) vim.keymap.set('n', 'gsta', 'Git stash push', { desc = 'Git stash' }) vim.keymap.set('n', 'gstA', 'Git stash apply', { desc = 'Git stash apply' }) vim.keymap.set('n', 'gstp', 'Git stash pop', { desc = 'Git stash pop' }) -- AI mappings vim.keymap.set('v', 'ae', 'CodeCompanion', { desc = 'Edit selection with AI' }) vim.keymap.set('n', 'ac', 'CodeCompanionCmd', { desc = 'Run Neovim commands with AI' }) -- Search mappings vim.keymap.set('n', 'sGb', 'Telescope git_branches', { desc = 'Search git branches' }) vim.keymap.set('n', 'sGc', 'Telescope git_commits', { desc = 'Search git history' }) vim.keymap.set('n', 'sGh', 'Telescope git_bcommits', { desc = 'Search git history within current buffer/selection' }) vim.keymap.set('n', 'sGs', 'Telescope git_status', { desc = 'Search git status' }) vim.keymap.set('n', 'sGS', 'Telescope git_stash', { desc = 'Search git stash' }) -- Misc vim.keymap.set('n', ']', 'cnext', { desc = 'Next item in quickfix list' }) vim.keymap.set('n', '[', 'cprevious', { desc = 'Previous item in quickfix list' }) vim.keymap.set('n', 'gd', 'Telescope lsp_definitions', { desc = 'Go to definition' }) -- Leaving this commented out, I will try the format command instead -- "A command to properly indent json code -- command! FormatJSON %!python -m json.tool require('helpers').edit_cf('k', '/lua/keymap.lua')