diff --git a/KEYMAPS.md b/KEYMAPS.md new file mode 100644 index 0000000..3b09495 --- /dev/null +++ b/KEYMAPS.md @@ -0,0 +1,183 @@ +# Neovim Keymaps + +**Leader key = `Space`** + +--- + +## File & Buffer + +| Key | What it does | +|-----|-------------| +| `w` | Save the current file | +| `q` | Quit Neovim | +| `c` | Close the current buffer | +| `bc` | Save all buffers, then close everything except the current one | + +--- + +## Navigation + +| Key | What it does | +|-----|-------------| +| `e` | Jump to end of line | +| `s` | Jump to first non-blank character of line | +| `cb` | Go back to previous location (like browser back) | +| `cf` | Go forward (undo a `cb`) | + +--- + +## Windows & Splits + +| Key | What it does | +|-----|-------------| +| `v` | Open a vertical split | +| `h` | Open a horizontal split | +| `Ctrl+h` | Move focus to the left window | +| `Ctrl+j` | Move focus to the window below | +| `Ctrl+k` | Move focus to the window above | +| `Ctrl+l` | Move focus to the right window | +| `Ctrl+Up` | Make current window shorter | +| `Ctrl+Down` | Make current window taller | +| `Ctrl+Left` | Make current window narrower | +| `Ctrl+Right` | Make current window wider | + +--- + +## File Tree (NERDTree) + +| Key | What it does | +|-----|-------------| +| `n` | Show/hide the file explorer sidebar | + +--- + +## Fuzzy Finder (Telescope) + +| Key | What it does | +|-----|-------------| +| `ff` | Search for files by name | +| `fg` | Search for text inside files (live grep) | +| `fb` | List all open buffers | +| `fh` | Search Neovim help topics | + +**Inside a Telescope window:** + +| Key | What it does | +|-----|-------------| +| `Ctrl+n` | Move to next result | +| `Ctrl+p` | Move to previous result | +| `Ctrl+d` | Delete the selected buffer | +| `Ctrl+c` | Close Telescope | + +--- + +## Clipboard + +| Key | What it does | +|-----|-------------| +| `y` (visual) | Copy selected text to system clipboard | +| `p` | Paste from system clipboard | + +--- + +## Search + +| Key | What it does | +|-----|-------------| +| `/` | Clear the search highlight | + +--- + +## LSP (Code Intelligence) + +| Key | What it does | +|-----|-------------| +| `gd` | Go to the definition of the symbol under cursor | +| `K` | Show documentation for the symbol under cursor | +| `rn` | Rename the symbol under cursor across the project | +| `gr` | Show all references to the symbol (opens in Trouble panel) | +| `f` | Format the current file using the LSP | +| `a` | Show code actions (quick fixes, refactors) | +| `d` | Show hover documentation (same as `K`) | + +--- + +## Comments (Comment.nvim) + +| Key | What it does | +|-----|-------------| +| `kk` | Toggle comment on the current line | +| `k` + motion | Comment/uncomment everything the motion covers (e.g. `k3j` comments 3 lines down) | +| `k` (visual) | Comment/uncomment the selected lines | +| `bb` | Toggle block comment on the current line | +| `b` + motion | Block comment everything the motion covers | +| `b` (visual) | Block comment the selection | + +--- + +## Diagnostics Panel (Trouble.nvim) + +Shows all LSP errors and warnings — across every file the language server knows about, like the Problems panel in VSCode. + +| Key | What it does | +|-----|-------------| +| `xx` | Toggle workspace diagnostics (all errors across the project) | +| `xd` | Toggle diagnostics for the current file only | +| `xq` | Open the quickfix list in Trouble | +| `xl` | Open the location list in Trouble | + +**Inside the Trouble panel:** + +| Key | What it does | +|-----|-------------| +| `j` / `k` | Move to next / previous item | +| `Enter` or `Tab` | Jump to that error in the file | +| `x` | Open the file in a horizontal split | +| `v` | Open the file in a vertical split | +| `p` | Preview the error location without leaving Trouble | +| `r` | Refresh the list | +| `za` | Toggle fold for a file group | +| `zm` | Collapse all file groups | +| `zr` | Expand all file groups | +| `q` | Close the Trouble panel | + +--- + +## Terminal + +| Key | What it does | +|-----|-------------| +| `t` | Open/close the terminal (toggles a split at the bottom) | +| `t` (inside terminal) | Close the terminal | + +--- + +## Testing (vim-test) + +| Key | What it does | +|-----|-------------| +| `tn` | Run the test nearest to the cursor | +| `tf` | Run all tests in the current file | +| `ts` | Run the entire test suite | +| `tl` | Re-run the last test that was run | +| `tv` | Open the test file that was last run | + +--- + +## Markdown Preview + +| Key | What it does | +|-----|-------------| +| `mp` | Open a browser preview of the current Markdown file | +| `ms` | Stop the Markdown preview | +| `mf` | Keep the preview scrolled to where your cursor is | +| `mt` | Toggle the Markdown preview on/off | + +--- + +## Utilities + +| Key | What it does | +|-----|-------------| +| `sr` | Search and replace (interactive prompt) | +| `cf` | Create a new Java file | diff --git a/init.lua b/init.lua index 165efc4..4ebed13 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,7 @@ require("user.autocmds") require("user.files_utils") require("user.commands") require("user.comment") +require("user.trouble") require("user.java") return require("packer").startup(function(use) @@ -71,6 +72,12 @@ return require("packer").startup(function(use) -- Comment use 'numToStr/Comment.nvim' + -- Trouble: workspace diagnostics panel + use { + "folke/trouble.nvim", + requires = { "nvim-tree/nvim-web-devicons" }, + } + -- Telescope FZF native use({ diff --git a/lua/user/comment.lua b/lua/user/comment.lua index 8bcf967..a384c03 100644 --- a/lua/user/comment.lua +++ b/lua/user/comment.lua @@ -7,11 +7,11 @@ end require("Comment").setup({ toggler = { - line = "k", -- Mapping for toggling comments - block = "b", -- Mapping for block comments + line = "kk", + block = "bb", }, opleader = { - line = "k", -- Mapping for operator-pending comments - block = "b", -- Mapping for block comments in operator-pending mode + line = "k", + block = "b", }, }) diff --git a/lua/user/trouble.lua b/lua/user/trouble.lua new file mode 100644 index 0000000..215e9d2 --- /dev/null +++ b/lua/user/trouble.lua @@ -0,0 +1,39 @@ +local status_ok, trouble = pcall(require, "trouble") +if not status_ok then + vim.notify("trouble.nvim not found!") + return +end + +trouble.setup({ + position = "bottom", + height = 15, + icons = true, + mode = "workspace_diagnostics", + severity = nil, + fold_open = "", + fold_closed = "", + action_keys = { + close = "q", + refresh = "r", + jump = { "", "" }, + open_split = "x", + open_vsplit = "v", + preview = "p", + close_folds = "zm", + open_folds = "zr", + toggle_fold = "za", + previous = "k", + next = "j", + }, + auto_preview = true, + use_diagnostic_signs = true, +}) + +local map = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +map("n", "xx", "TroubleToggle workspace_diagnostics", opts) +map("n", "xd", "TroubleToggle document_diagnostics", opts) +map("n", "xq", "TroubleToggle quickfix", opts) +map("n", "xl", "TroubleToggle loclist", opts) +map("n", "gr", "TroubleToggle lsp_references", opts)