From c54b71fdd43fc1e3a0bdb068a21df2cedff1954f Mon Sep 17 00:00:00 2001 From: sharmaharshitnone Date: Sat, 14 Jun 2025 09:15:11 +0530 Subject: [PATCH] done maybe --- .stylua.toml | 1 + README.md | 79 ++-- debug.lua.bak | 179 -------- disable_flow_control.sh | 9 - init.lua | 162 +++++--- lua/custom/keybinding_cheatsheet.md | 50 +++ lua/custom/keybindings_ref.md | 182 +++++++++ lua/custom/keybindings_reference.md | 187 +++++++++ lua/custom/keymaps.lua | 113 ++++++ lua/custom/keymaps_reference.md | 196 +++++++++ lua/custom/plugin_keymaps.lua | 270 ++++++++++++ lua/custom/plugins/copilot-chat.lua | 383 +++++++++++------- lua/custom/plugins/init.lua | 2 + lua/custom/plugins/jdtls_config.lua | 52 +++ lua/custom/plugins/leetcode.lua | 82 ++-- lua/custom/plugins/neorg.lua | 185 +++++++++ lua/custom/plugins/neorg_guide.md | 310 ++++++++++++++ lua/custom/plugins/neorg_keymaps_reference.md | 129 ++++++ .../plugins/neorg_optimization_summary.md | 82 ++++ lua/custom/plugins/telescope_fix.lua.back | 34 -- lua/custom/plugins/trouble.lua | 19 +- lua/custom/plugins/which_key_integration.lua | 275 +++++++++++++ lua/custom/utils/neorg_setup_check.lua | 0 lua/custom/which_key_setup.lua | 152 +++++++ 24 files changed, 2632 insertions(+), 501 deletions(-) delete mode 100644 debug.lua.bak delete mode 100644 disable_flow_control.sh create mode 100644 lua/custom/keybinding_cheatsheet.md create mode 100644 lua/custom/keybindings_ref.md create mode 100644 lua/custom/keybindings_reference.md create mode 100644 lua/custom/keymaps.lua create mode 100644 lua/custom/keymaps_reference.md create mode 100644 lua/custom/plugin_keymaps.lua create mode 100644 lua/custom/plugins/jdtls_config.lua create mode 100644 lua/custom/plugins/neorg.lua create mode 100644 lua/custom/plugins/neorg_guide.md create mode 100644 lua/custom/plugins/neorg_keymaps_reference.md create mode 100644 lua/custom/plugins/neorg_optimization_summary.md delete mode 100644 lua/custom/plugins/telescope_fix.lua.back create mode 100644 lua/custom/plugins/which_key_integration.lua create mode 100644 lua/custom/utils/neorg_setup_check.lua create mode 100644 lua/custom/which_key_setup.lua diff --git a/.stylua.toml b/.stylua.toml index 139e9397..6bc6d94f 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,3 +1,4 @@ +# filepath: /home/kali/.config/nvim/.stylua.toml column_width = 160 line_endings = "Unix" indent_type = "Spaces" diff --git a/README.md b/README.md index 41139505..79e811ae 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ A starting point for Neovim that is: -* Small -* Single-file -* Completely Documented +- Small +- Single-file +- Completely Documented **NOT** a Neovim distribution, but instead a starting point for your configuration. @@ -14,7 +14,7 @@ A starting point for Neovim that is: ### Install Neovim -Kickstart.nvim targets *only* the latest +Kickstart.nvim targets _only_ the latest ['stable'](https://github.com/neovim/neovim/releases/tag/stable) and latest ['nightly'](https://github.com/neovim/neovim/releases/tag/nightly) of Neovim. If you are experiencing issues, please make sure you have the latest versions. @@ -22,13 +22,16 @@ If you are experiencing issues, please make sure you have the latest versions. ### Install External Dependencies External Requirements: + - Basic utils: `git`, `make`, `unzip`, C Compiler (`gcc`) - [ripgrep](https://github.com/BurntSushi/ripgrep#installation), [fd-find](https://github.com/sharkdp/fd#installation) - Clipboard tool (xclip/xsel/win32yank or other depending on the platform) - A [Nerd Font](https://www.nerdfonts.com/): optional, provides various icons - if you have it set `vim.g.have_nerd_font` in `init.lua` to true -- Emoji fonts (Ubuntu only, and only if you want emoji!) `sudo apt install fonts-noto-color-emoji` +- Emoji fonts (only if you want emoji!) + - On Arch Linux: `sudo pacman -S noto-fonts-emoji` or `yay -S noto-fonts-emoji` + - On Ubuntu: `sudo apt install fonts-noto-color-emoji` - Language Setup: - If you want to write Typescript, you need `npm` - If you want to write Golang, you will need `go` @@ -40,16 +43,15 @@ External Requirements: ### Install Kickstart -> [!NOTE] -> [Backup](#FAQ) your previous configuration (if any exists) +> [!NOTE] > [Backup](#FAQ) your previous configuration (if any exists) Neovim's configurations are located under the following paths, depending on your OS: -| OS | PATH | -| :- | :--- | -| Linux, MacOS | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` | -| Windows (cmd)| `%localappdata%\nvim\` | -| Windows (powershell)| `$env:LOCALAPPDATA\nvim\` | +| OS | PATH | +| :------------------- | :---------------------------------------- | +| Linux, MacOS | `$XDG_CONFIG_HOME/nvim`, `~/.config/nvim` | +| Windows (cmd) | `%localappdata%\nvim\` | +| Windows (powershell) | `$env:LOCALAPPDATA\nvim\` | #### Recommended Step @@ -115,19 +117,18 @@ examples of adding popularly requested plugins. > [!NOTE] > For more information about a particular plugin check its repository's documentation. - ### Getting Started [The Only Video You Need to Get Started with Neovim](https://youtu.be/m8C0Cq9Uv9o) ### FAQ -* What should I do if I already have a pre-existing Neovim configuration? - * You should back it up and then delete all associated files. - * This includes your existing init.lua and the Neovim files in `~/.local` +- What should I do if I already have a pre-existing Neovim configuration? + - You should back it up and then delete all associated files. + - This includes your existing init.lua and the Neovim files in `~/.local` which can be deleted with `rm -rf ~/.local/share/nvim/` -* Can I keep my existing configuration in parallel to kickstart? - * Yes! You can use [NVIM_APPNAME](https://neovim.io/doc/user/starting.html#%24NVIM_APPNAME)`=nvim-NAME` +- Can I keep my existing configuration in parallel to kickstart? + - Yes! You can use [NVIM_APPNAME](https://neovim.io/doc/user/starting.html#%24NVIM_APPNAME)`=nvim-NAME` to maintain multiple configurations. For example, you can install the kickstart configuration in `~/.config/nvim-kickstart` and create an alias: ``` @@ -137,18 +138,18 @@ examples of adding popularly requested plugins. config directory and the matching local directory `~/.local/share/nvim-kickstart`. You can apply this approach to any Neovim distribution that you would like to try out. -* What if I want to "uninstall" this configuration: - * See [lazy.nvim uninstall](https://lazy.folke.io/usage#-uninstalling) information -* Why is the kickstart `init.lua` a single file? Wouldn't it make sense to split it into multiple files? - * The main purpose of kickstart is to serve as a teaching tool and a reference +- What if I want to "uninstall" this configuration: + - See [lazy.nvim uninstall](https://lazy.folke.io/usage#-uninstalling) information +- Why is the kickstart `init.lua` a single file? Wouldn't it make sense to split it into multiple files? + - The main purpose of kickstart is to serve as a teaching tool and a reference configuration that someone can easily use to `git clone` as a basis for their own. As you progress in learning Neovim and Lua, you might consider splitting `init.lua` into smaller parts. A fork of kickstart that does this while maintaining the same functionality is available here: - * [kickstart-modular.nvim](https://github.com/dam9000/kickstart-modular.nvim) - * Discussions on this topic can be found here: - * [Restructure the configuration](https://github.com/nvim-lua/kickstart.nvim/issues/218) - * [Reorganize init.lua into a multi-file setup](https://github.com/nvim-lua/kickstart.nvim/pull/473) + - [kickstart-modular.nvim](https://github.com/dam9000/kickstart-modular.nvim) + - Discussions on this topic can be found here: + - [Restructure the configuration](https://github.com/nvim-lua/kickstart.nvim/issues/218) + - [Reorganize init.lua into a multi-file setup](https://github.com/nvim-lua/kickstart.nvim/pull/473) ### Install Recipes @@ -170,23 +171,27 @@ This requires: ```lua {'nvim-telescope/telescope-fzf-native.nvim', build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' } ``` +
Windows with gcc/make using chocolatey Alternatively, one can install gcc and make which don't require changing the config, the easiest way is to use choco: 1. install [chocolatey](https://chocolatey.org/install) -either follow the instructions on the page or use winget, -run in cmd as **admin**: + either follow the instructions on the page or use winget, + run in cmd as **admin**: + ``` winget install --accept-source-agreements chocolatey.chocolatey ``` 2. install all requirements using choco, exit the previous cmd and -open a new one so that choco path is set, and run in cmd as **admin**: + open a new one so that choco path is set, and run in cmd as **admin**: + ``` choco install -y neovim git ripgrep wget fd unzip gzip mingw make ``` +
WSL (Windows Subsystem for Linux) @@ -197,9 +202,20 @@ sudo add-apt-repository ppa:neovim-ppa/unstable -y sudo apt update sudo apt install make gcc ripgrep unzip git xclip neovim ``` +
#### Linux Install + +
Arch Linux Install Steps + +``` +sudo pacman -S neovim make gcc ripgrep unzip git xclip +# If you need additional packages from AUR, use yay: +# yay -S neovim-git # For the git version of neovim +``` + +
Ubuntu Install Steps ``` @@ -207,6 +223,7 @@ sudo add-apt-repository ppa:neovim-ppa/unstable -y sudo apt update sudo apt install make gcc ripgrep unzip git xclip neovim ``` +
Debian Install Steps @@ -224,12 +241,14 @@ sudo tar -C /opt -xzf nvim-linux-x86_64.tar.gz # make it available in /usr/local/bin, distro installs to /usr/bin sudo ln -sf /opt/nvim-linux-x86_64/bin/nvim /usr/local/bin/ ``` +
Fedora Install Steps ``` sudo dnf install -y gcc make git ripgrep fd-find unzip neovim ``` +
Arch Install Steps @@ -237,5 +256,5 @@ sudo dnf install -y gcc make git ripgrep fd-find unzip neovim ``` sudo pacman -S --noconfirm --needed gcc make git ripgrep fd unzip neovim ``` -
+ diff --git a/debug.lua.bak b/debug.lua.bak deleted file mode 100644 index 1bc7501c..00000000 --- a/debug.lua.bak +++ /dev/null @@ -1,179 +0,0 @@ --- debug.lua --- --- Shows how to use the DAP plugin to debug your code. --- --- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. That's why it's called --- kickstart.nvim and not kitchen-sink.nvim ;) - -return { - -- NOTE: Yes, you can install new plugins here! - 'mfussenegger/nvim-dap', - -- NOTE: And you can specify dependencies as well - dependencies = { - -- Creates a beautiful debugger UI - 'rcarriga/nvim-dap-ui', - - -- Required dependency for nvim-dap-ui - 'nvim-neotest/nvim-nio', - - -- Installs the debug adapters for you - 'williamboman/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', - - -- Add your own debuggers here - 'leoluz/nvim-dap-go', - 'mfussenegger/nvim-dap-python', -- Uncomment to add Python support - 'theHamsta/nvim-dap-virtual-text', -- Uncomment to add virtual text support - }, - keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - 'g@', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - {Read debug.lua, lines 1 to 153 - - - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - '.', - function() - require('dap').toggle_breakpoint() - end, - desc = 'Debug: Toggle Breakpoint', - }, - { - 'B', - function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') - end, - desc = 'Debug: Set Breakpoint', - }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. - { - '', - function() - require('dapui').toggle() - end, - desc = 'Debug: See last session result.', - }, - }, - config = function() - local dap = require 'dap' - local dapui = require 'dapui' - - require('mason-nvim-dap').setup { - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations - automatic_installation = true, - - -- You can provide additional configuration to the handlers, - -- see mason-nvim-dap README for more information - handlers = {}, - - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) - ensure_installed = { - -- Update this to ensure that you have the debuggers for the langs you want - 'delve', - 'debugpy', -- Python debugger - }, - } - - -- Dap UI setup - -- For more information, see |:help nvim-dap-ui| - dapui.setup { - -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. - icons = { expanded = '▾', collapsed = '▸', current_frame = '*' }, - controls = { - icons = { - pause = '⏸', - play = '▶', - step_into = '⏎', - step_over = '⏭', - step_out = '⏮', - step_back = 'b', - run_last = '▶▶', - terminate = '⏹', - disconnect = '⏏', - }, - }, - } - - -- Change breakpoint icons - -- vim.api.nvim_set_hl(0, 'DapBreak', { fg = '#e51400' }) - -- vim.api.nvim_set_hl(0, 'DapStop', { fg = '#ffcc00' }) - -- local breakpoint_icons = vim.g.have_nerd_font - -- and { Breakpoint = '', BreakpointCondition = '', BreakpointRejected = '', LogPoint = '', Stopped = '' } - -- or { Breakpoint = '●', BreakpointCondition = '⊜', BreakpointRejected = '⊘', LogPoint = '◆', Stopped = '⭔' } - -- for type, icon in pairs(breakpoint_icons) do - -- local tp = 'Dap' .. type - -- local hl = (type == 'Stopped') and 'DapStop' or 'DapBreak' - -- vim.fn.sign_define(tp, { text = icon, texthl = hl, numhl = hl }) - -- end - - dap.listeners.after.event_initialized['dapui_config'] = dapui.open - dap.listeners.before.event_terminated['dapui_config'] = dapui.close - dap.listeners.before.event_exited['dapui_config'] = dapui.close - - -- Install golang specific config - require('dap-go').setup { - delve = { - -- On Windows delve must be run attached or it crashes. - -- See https://github.com/leoluz/nvim-dap-go/blob/main/README.md#configuring - detached = vim.fn.has 'win32' == 0, - }, - } - - -- Python configuration - require('dap-python').setup('python') -- Uses the Python in your PATH - require('dap-python').test_runner = 'pytest' - - -- Make sure the configurations table exists - dap.configurations.python = dap.configurations.python or {} - - -- Add some common Python debug configurations - table.insert(dap.configurations.python, { - type = 'python', - request = 'launch', - name = 'Launch file', - program = '${file}', - pythonPath = function() - -- Try to detect python path from virtual environment - local cwd = vim.fn.getcwd() - if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then - return cwd .. '/venv/bin/python' - elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then - return cwd .. '/.venv/bin/python' - else - return 'python' - end - end, - }) - end, -} diff --git a/disable_flow_control.sh b/disable_flow_control.sh deleted file mode 100644 index e4ec8eab..00000000 --- a/disable_flow_control.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Disable flow control (Ctrl+S, Ctrl+Q) in the terminal -# This allows Ctrl+S to be used for saving in Neovim -stty -ixon - -# Optional: You can also add this line to make Ctrl+S work in programs that use readline -# (like the bash/zsh command line itself) -if [ -t 0 ]; then - bind -r '\C-s' 2>/dev/null || true -fi diff --git a/init.lua b/init.lua index de1cc296..14cfa8b1 100644 --- a/init.lua +++ b/init.lua @@ -91,6 +91,9 @@ local vim = vim vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +-- Test leader key mapping +vim.keymap.set('n', 'zz', function() print("Leader key is working!") end, { desc = "Test leader key" }) + -- Set to true if you have a Nerd Font installed and selected in the terminal vim.g.have_nerd_font = true @@ -320,59 +323,112 @@ require('lazy').setup({ -- Then, because we use the `opts` key (recommended), the configuration runs -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - { -- Useful plugin to show you pending keybinds. - 'folke/which-key.nvim', - event = 'VimEnter', -- Sets the loading event to 'VimEnter' - opts = { - -- delay between pressing a key and opening which-key (milliseconds) - -- this setting is independent of vim.o.timeoutlen - delay = 0, - icons = { - -- set icon mappings to true if you have a Nerd Font - mappings = vim.g.have_nerd_font, - -- If you are using a Nerd Font: set icons.keys to an empty table which will use the - -- default which-key.nvim defined Nerd Font icons, otherwise define a string table - keys = vim.g.have_nerd_font and {} or { - Up = ' ', - Down = ' ', - Left = ' ', - Right = ' ', - C = ' ', - M = ' ', - D = ' ', - S = ' ', - CR = ' ', - Esc = ' ', - ScrollWheelDown = ' ', - ScrollWheelUp = ' ', - NL = ' ', - BS = ' ', - Space = ' ', - Tab = ' ', - F1 = '', - F2 = '', - F3 = '', - F4 = '', - F5 = '', - F6 = '', - F7 = '', - F8 = '', - F9 = '', - F10 = '', - F11 = '', - F12 = '', - }, - }, + -- NOTE: which-key is now configured in custom/plugins/which_key_integration.lua + -- { -- Useful plugin to show you pending keybinds. + -- 'folke/which-key.nvim', + -- event = 'VimEnter', -- Sets the loading event to 'VimEnter' + -- opts = { + -- -- delay between pressing a key and opening which-key (milliseconds) + -- -- this setting is independent of vim.o.timeoutlen + -- delay = 0, + -- icons = { + -- -- set icon mappings to true if you have a Nerd Font + -- mappings = vim.g.have_nerd_font, + -- -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- -- default which-key.nvim defined Nerd Font icons, otherwise define a string table + -- keys = vim.g.have_nerd_font and {} or { + -- Up = ' ', + -- Down = ' ', -- { -- Useful plugin to show you pending keybinds. + -- 'folke/which-key.nvim', + -- event = 'VimEnter', -- Sets the loading event to 'VimEnter' + -- opts = { + -- -- delay between pressing a key and opening which-key (milliseconds) + -- -- this setting is independent of vim.o.timeoutlen + -- delay = 0, + -- icons = { + -- -- set icon mappings to true if you have a Nerd Font + -- mappings = vim.g.have_nerd_font, + -- -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- -- default which-key.nvim defined Nerd Font icons, otherwise define a string table + -- keys = vim.g.have_nerd_font and {} or { + -- Up = ' ', + -- Down = ' ', + -- Left = ' ', + -- Right = ' ', + -- C = ' ', + -- M = ' ', + -- D = ' ', + -- S = ' ', + -- CR = ' ', + -- Esc = ' ', + -- ScrollWheelDown = ' ', + -- ScrollWheelUp = ' ', + -- NL = ' ', + -- BS = ' ', + -- Space = ' ', + -- Tab = ' ', + -- F1 = '', + -- F2 = '', + -- F3 = '', + -- F4 = '', + -- F5 = '', + -- F6 = '', + -- F7 = '', + -- F8 = '', + -- F9 = '', + -- F10 = '', + -- F11 = '', + -- F12 = '', + -- }, + -- }, - -- Document existing key chains - spec = { - { 's', group = '[S]earch' }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, - { 'b', group = '[B]uffer' }, - }, - }, - }, + -- -- Document existing key chains + -- spec = { + -- { 's', group = '[S]earch' }, + -- { 't', group = '[T]oggle' }, + -- { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + -- { 'b', group = '[B]uffer' }, + -- }, + -- }, + -- }, + -- Left = ' ', + -- Right = ' ', + -- C = ' ', + -- M = ' ', + -- D = ' ', + -- S = ' ', + -- CR = ' ', + -- Esc = ' ', + -- ScrollWheelDown = ' ', + -- ScrollWheelUp = ' ', + -- NL = ' ', + -- BS = ' ', + -- Space = ' ', + -- Tab = ' ', + -- F1 = '', + -- F2 = '', + -- F3 = '', + -- F4 = '', + -- F5 = '', + -- F6 = '', + -- F7 = '', + -- F8 = '', + -- F9 = '', + -- F10 = '', + -- F11 = '', + -- F12 = '', + -- }, + -- }, + + -- -- Document existing key chains + -- spec = { + -- { 's', group = '[S]earch' }, + -- { 't', group = '[T]oggle' }, + -- { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + -- { 'b', group = '[B]uffer' }, + -- }, + -- }, + -- }, -- NOTE: Plugins can specify dependencies. -- @@ -458,7 +514,7 @@ require('lazy').setup({ vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', '', function() builtin.buffers() end, { desc = '[ ] Find existing buffers' }) + vim.keymap.set('n', 'bb', function() builtin.buffers() end, { desc = '[B]uffers [B]rowse' }) -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() diff --git a/lua/custom/keybinding_cheatsheet.md b/lua/custom/keybinding_cheatsheet.md new file mode 100644 index 00000000..c2dfa653 --- /dev/null +++ b/lua/custom/keybinding_cheatsheet.md @@ -0,0 +1,50 @@ +# Neovim Keybinding Cheatsheet + +## General + +| Key | Mode | Description | +| ----------- | ---- | ----------------------- | +| `w` | n | Save file | +| `q` | n | Quit | +| `Q` | n | Force quit all | +| `W` | n | Save and quit | +| `/` | n | Clear search highlights | +| `` | n | Clear highlights | + +## Navigation + +### Window Navigation + +| Key | Mode | Description | +| ------- | ---- | -------------------- | +| `` | n | Move to left window | +| `` | n | Move to lower window | +| `` | n | Move to upper window | +| `` | n | Move to right window | + +### Window Management (`w`) + +| Key | Mode | Description | +| ------------ | ---- | ------------------------- | +| `wv` | n | Split window vertically | +| `ws` | n | Split window horizontally | +| `wq` | n | Close current window | +| `wo` | n | Close other windows | +| `wh` | n | Go to left window | +| `wj` | n | Go to lower window | +| `wk` | n | Go to upper window | +| `wl` | n | Go to right window | + +### Window Resizing + +| Key | Mode | Description | +| ----------- | ---- | ---------------------- | +| `` | n | Increase window height | +| `` | n | Decrease window height | +| `` | n | Decrease window width | +| `` | n | Increase window width | + +### Tab Management (`t`) + +| Key | Mode | Description | +| --- | ---- | ----------- | diff --git a/lua/custom/keybindings_ref.md b/lua/custom/keybindings_ref.md new file mode 100644 index 00000000..a7354e24 --- /dev/null +++ b/lua/custom/keybindings_ref.md @@ -0,0 +1,182 @@ +# Neovim Keybindings Reference + +A comprehensive reference for all keybindings in this Neovim configuration, organized by prefix and functionality. + +## General Operations + +- `w` - Save file +- `q` - Quit +- `Q` - Force quit all +- `W` - Save and quit +- `/` - Clear search highlights +- `` - Clear highlights + +## Navigation + +### Window Navigation + +- `` - Move focus to the left window +- `` - Move focus to the down window +- `` - Move focus to the up window +- `` - Move focus to the right window + +### Window Management (`w`) + +- `wv` - Split window vertically +- `ws` - Split window horizontally +- `wq` - Close current window +- `wo` - Close other windows + +### Window Resizing + +- `` - Increase window height +- `` - Decrease window height +- `` - Decrease window width +- `` - Increase window width + +### Tab Management (`t`) + +- `tn` - New tab +- `to` - New tab with file +- `tc` - Close tab +- `` - Next tab +- `` - Previous tab + +### Buffer Navigation (`b`) + +- `` - Find buffers +- `bd` - Delete buffer +- `bn` - Next buffer +- `bp` - Previous buffer +- `bp` - Pick buffer +- `bc` - Pick buffer to close +- `bh` - Previous buffer +- `bl` - Next buffer +- `bH` - Move buffer left +- `bL` - Move buffer right +- `b1-9` - Go to buffer 1-9 +- `` - Go to buffer 1-9 + +## File Operations (`f`) + +### File Search (Telescope) + +- `ff` - Find files +- `fg` - Live grep +- `fb` - Find buffers +- `fh` - Help tags +- `fr` - Recent files +- `fc` - Grep current string +- `fk` - Find keymaps +- `fd` - Search diagnostics +- `fw` - Search current buffer + +### Git Search (`fg`) + +- `fgc` - Git commits +- `fgb` - Git branches +- `fgs` - Git status +- `fgt` - Git stash + +### File Explorer + +- `e` - Open file explorer + +## Editing + +### Line Movement + +- `` - Move line down +- `` - Move line up +- `` (visual) - Move selection down +- `` (visual) - Move selection up + +### Indentation + +- `<` (visual) - Decrease indent +- `>` (visual) - Increase indent + +## Terminal (`tt`) + +- `tt` - Toggle terminal +- `tf` - Toggle floating terminal +- `th` - Toggle horizontal terminal +- `tv` - Toggle vertical terminal +- `` (terminal) - Exit terminal mode + +## Diagnostics (`x`) + +- `xx` - Toggle trouble +- `xw` - Toggle workspace diagnostics +- `xd` - Toggle document diagnostics / Open diagnostic float +- `xq` - Toggle quickfix +- `xl` - Toggle location list / Open diagnostic list +- `[d` - Previous diagnostic +- `]d` - Next diagnostic + +## Plugin-specific Keybindings + +### Harpoon (`h`) + +- `ha` - Add file to harpoon +- `hh` - Toggle quick menu +- `h1-9` - Jump to file 1-9 + +### LeetCode (`l`) + +- `ll` - Open LeetCode +- `ld` - Daily Challenge +- `lr` - Random Problem +- `ls` - Submit Solution +- `lt` - Test Solution +- `lm` - LeetCode Menu +- `li` - Problem Info +- `lc` - Toggle Console +- `la` - Switch Tab + +### Neorg (`n`) + +- `ni` - Neorg index +- `nr` - Return from workspace +- `nt` - Toggle concealer +- `nm` - Inject metadata + +#### Neorg Journal (`nj`) + +- `njj` - Today's journal entry +- `njt` - Tomorrow's journal entry +- `njy` - Yesterday's journal entry + +#### Neorg Workspace (`nw`) + +- `nwn` - Switch to notes workspace +- `nww` - Switch to work workspace +- `nwp` - Switch to personal workspace + +#### Neorg Export (`ne`) + +- `neh` - Export to HTML +- `nem` - Export to Markdown +- `nep` - Export to PDF + +### LSP (`ls`) + +- `lsr` - Rename symbol +- `lsa` - Code actions +- `lsf` - Format document +- `lsd` - Go to definition +- `lst` - Go to type definition +- `lsD` - Go to declaration +- `lsi` - Go to implementation +- `lsr` - Go to references + +### Test (`te`) + +- `ter` - Run test +- `tes` - Run test suite +- `tef` - Run test file +- `tel` - Run last test + +### Code/Copilot (`c`) + +- Various code and Copilot-related commands diff --git a/lua/custom/keybindings_reference.md b/lua/custom/keybindings_reference.md new file mode 100644 index 00000000..be820fc3 --- /dev/null +++ b/lua/custom/keybindings_reference.md @@ -0,0 +1,187 @@ +# Neovim Keybindings Reference + +This document provides a comprehensive reference for all keybindings in this Neovim configuration, organized by category. + +## Navigation + +### Window Navigation + +- `` - Move focus to the left window +- `` - Move focus to the down window +- `` - Move focus to the up window +- `` - Move focus to the right window + +### Window Management + +- `wv` - Split window vertically +- `ws` - Split window horizontally +- `wq` - Close current window +- `wo` - Close other windows + +### Window Resizing + +- `` - Increase window height +- `` - Decrease window height +- `` - Decrease window width +- `` - Increase window width + +### Tab Management + +- `tn` - New tab +- `to` - New tab with file +- `tc` - Close tab +- `` - Next tab +- `` - Previous tab + +### Buffer Navigation + +- `` - Find buffers +- `bd` - Delete buffer +- `bn` - Next buffer +- `bp` - Previous buffer + +## File Operations + +### General Operations + +- `w` - Save file +- `q` - Quit +- `Q` - Force quit all +- `W` - Save and quit +- `/` - Clear search highlights +- `` - Clear highlights + +### File Explorer + +- `e` - Open file explorer + +## Search and Navigation (Telescope) + +### General Search + +- `ff` - Find files +- `fg` - Live grep +- `fb` - Find buffers +- `fh` - Help tags +- `fr` - Recent files +- `fc` - Grep current string +- `fk` - Find keymaps +- `fd` - Search diagnostics +- `fw` - Search current buffer + +### Git Search + +- `fgc` - Git commits +- `fgb` - Git branches +- `fgs` - Git status +- `fgt` - Git stash + +## Bufferline + +### Buffer Actions + +- `bp` - Pick buffer +- `bc` - Pick buffer to close +- `bh` - Previous buffer +- `bl` - Next buffer +- `bH` - Move buffer left +- `bL` - Move buffer right +- `b1-9` - Go to buffer 1-9 +- `` - Go to buffer 1-9 + +## Editing + +### Line Movement + +- `` - Move line down +- `` - Move line up +- `` (visual) - Move selection down +- `` (visual) - Move selection up + +### Indentation + +- `<` (visual) - Decrease indent +- `>` (visual) - Increase indent + +## Terminal + +### Terminal Commands + +- `tt` - Toggle terminal +- `tf` - Toggle floating terminal +- `th` - Toggle horizontal terminal +- `tv` - Toggle vertical terminal +- `` (terminal) - Exit terminal mode + +## Diagnostics + +### Diagnostic Navigation + +- `xd` - Open diagnostic float +- `xl` - Open diagnostic list +- `[d` - Previous diagnostic +- `]d` - Next diagnostic + +## Plugin-specific Keybindings + +### Harpoon + +- `ha` - Add file to harpoon +- `hh` - Toggle quick menu +- `h1-9` - Jump to file 1-9 + +### LeetCode + +- `ll` - Open LeetCode +- `ld` - Daily Challenge +- `lr` - Random Problem +- `ls` - Submit Solution +- `lt` - Test Solution +- `lm` - LeetCode Menu +- `li` - Problem Info +- `lc` - Toggle Console +- `la` - Switch Tab + +### Trouble/Diagnostics + +- `xx` - Toggle trouble +- `xw` - Toggle workspace diagnostics +- `xd` - Toggle document diagnostics +- `xq` - Toggle quickfix +- `xl` - Toggle location list + +### Neorg + +- `ni` - Neorg index +- `nr` - Return from workspace +- `nt` - Toggle concealer +- `nm` - Inject metadata + +#### Neorg Journal + +- `njj` - Today's journal entry +- `njt` - Tomorrow's journal entry +- `njy` - Yesterday's journal entry + +#### Neorg Workspace + +- `nwn` - Switch to notes workspace +- `nww` - Switch to work workspace +- `nwp` - Switch to personal workspace + +#### Neorg Export + +- `neh` - Export to HTML +- `nem` - Export to Markdown +- `nep` - Export to PDF + +### LSP + +- `lsr` - Rename symbol +- `lsa` - Code actions +- `lsf` - Format document +- `lsd` - Go to definition +- `lst` - Go to type definition +- `lsD` - Go to declaration +- `lsi` - Go to implementation +- `lsr` - Go to references diff --git a/lua/custom/keymaps.lua b/lua/custom/keymaps.lua new file mode 100644 index 00000000..db61aa44 --- /dev/null +++ b/lua/custom/keymaps.lua @@ -0,0 +1,113 @@ +--[[ + 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 diff --git a/lua/custom/keymaps_reference.md b/lua/custom/keymaps_reference.md new file mode 100644 index 00000000..828b5933 --- /dev/null +++ b/lua/custom/keymaps_reference.md @@ -0,0 +1,196 @@ +# Neovim Keybindings Reference + +This document provides a comprehensive reference for all keybindings in your Neovim configuration. + +## Table of Contents + +- [General Keybindings](#general-keybindings) +- [Navigation](#navigation) +- [Editing](#editing) +- [UI & Terminal](#ui--terminal) +- [Plugin Keybindings](#plugin-keybindings) + - [Telescope](#telescope) + - [Bufferline](#bufferline) + - [Harpoon](#harpoon) + - [Git](#git) + - [Copilot](#copilot) + - [Neorg](#neorg) + - [LeetCode](#leetcode) + +## General Keybindings + +| Keybinding | Mode | Description | +| ----------- | ------ | ----------------------- | +| `w` | Normal | Save file | +| `q` | Normal | Quit | +| `Q` | Normal | Force quit all | +| `W` | Normal | Save and quit | +| `/` | Normal | Clear search highlights | +| `` | Normal | Clear highlights | + +## Navigation + +### Window Navigation + +| Keybinding | Mode | Description | +| ---------- | ------ | -------------------------- | +| `` | Normal | Move focus to left window | +| `` | Normal | Move focus to down window | +| `` | Normal | Move focus to up window | +| `` | Normal | Move focus to right window | + +### Window Management + +| Keybinding | Mode | Description | +| ------------ | ------ | ------------------------- | +| `wv` | Normal | Split window vertically | +| `ws` | Normal | Split window horizontally | +| `wq` | Normal | Close current window | +| `wo` | Normal | Close other windows | +| `` | Normal | Increase window height | +| `` | Normal | Decrease window height | +| `` | Normal | Decrease window width | +| `` | Normal | Increase window width | + +### Tab Management + +| Keybinding | Mode | Description | +| ------------ | ------ | ----------------- | +| `tn` | Normal | New tab | +| `to` | Normal | New tab with file | +| `tc` | Normal | Close tab | +| `` | Normal | Next tab | +| `` | Normal | Previous tab | + +### Buffer Navigation + +| Keybinding | Mode | Description | +| ------------------ | ------ | --------------- | +| `` | Normal | Find buffers | +| `bd` | Normal | Delete buffer | +| `bn` | Normal | Next buffer | +| `bp` | Normal | Previous buffer | + +## Editing + +| Keybinding | Mode | Description | +| ---------- | ------ | ---------------------------- | +| `` | Normal | Move line down | +| `` | Normal | Move line up | +| `` | Visual | Move selection down | +| `` | Visual | Move selection up | +| `<` | Visual | Decrease indent and reselect | +| `>` | Visual | Increase indent and reselect | + +## UI & Terminal + +| Keybinding | Mode | Description | +| ------------ | -------- | -------------------------- | +| `e` | Normal | Open file explorer | +| `tt` | Normal | Toggle terminal | +| `tf` | Normal | Toggle floating terminal | +| `th` | Normal | Toggle horizontal terminal | +| `tv` | Normal | Toggle vertical terminal | +| `` | Terminal | Exit terminal mode | + +### Diagnostics + +| Keybinding | Mode | Description | +| ------------ | ------ | --------------------- | +| `xd` | Normal | Open diagnostic float | +| `xl` | Normal | Open diagnostic list | +| `[d` | Normal | Previous diagnostic | +| `]d` | Normal | Next diagnostic | + +## Plugin Keybindings + +### Telescope + +| Keybinding | Mode | Description | +| ------------- | ------ | ------------------- | +| `ff` | Normal | Find files | +| `fg` | Normal | Live grep | +| `fb` | Normal | Find buffers | +| `fh` | Normal | Help tags | +| `fr` | Normal | Recent files | +| `fc` | Normal | Grep current string | +| `fk` | Normal | Find keymaps | +| `fgc` | Normal | Git commits | +| `fgb` | Normal | Git branches | +| `fgs` | Normal | Git status | + +### Bufferline + +| Keybinding | Mode | Description | +| ------------------ | ------ | -------------------- | +| `bp` | Normal | Pick buffer | +| `bc` | Normal | Pick buffer to close | +| `bh` | Normal | Previous buffer | +| `bl` | Normal | Next buffer | +| `bH` | Normal | Move buffer left | +| `bL` | Normal | Move buffer right | +| `` to `` | Normal | Go to buffer 1-9 | + +### Harpoon + +| Keybinding | Mode | Description | +| ---------------------------- | ------ | ------------------------ | +| `ha` | Normal | Add file to harpoon | +| `hm` | Normal | Open harpoon menu | +| `h1` to `h9` | Normal | Jump to harpoon file 1-9 | +| `` | Normal | Next harpoon file | +| `` | Normal | Previous harpoon file | + +### Git + +| Keybinding | Mode | Description | +| ------------ | ------ | -------------------- | +| `gg` | Normal | Open LazyGit | +| `gc` | Normal | Open LazyGit config | +| `gf` | Normal | LazyGit current file | + +### Copilot + +| Keybinding | Mode | Description | +| ------------ | ------ | -------------------------------- | +| `cc` | Normal | Copilot chat | +| `ce` | Normal | Explain code | +| `cf` | Normal | Fix code | +| `co` | Normal | Optimize code | +| `cd` | Normal | Generate documentation | +| `ct` | Normal | Generate tests | +| `cb` | Normal | Check best practices | +| `ce` | Visual | Explain selected code | +| `cf` | Visual | Fix selected code | +| `co` | Visual | Optimize selected code | +| `cd` | Visual | Document selected code | +| `ct` | Visual | Generate tests for selected code | + +### Neorg + +| Keybinding | Mode | Description | +| ------------- | ------ | ---------------------------- | +| `nj` | Normal | Open today's journal | +| `nyt` | Normal | Open yesterday's journal | +| `ntm` | Normal | Open tomorrow's journal | +| `nw` | Normal | Open workspace selector | +| `nn` | Normal | Switch to notes workspace | +| `nwp` | Normal | Switch to personal workspace | +| `ntt` | Normal | Generate table of contents | +| `ni` | Normal | Inject metadata | +| `nm` | Normal | Update metadata | +| `nc` | Normal | Toggle concealer | +| `nem` | Normal | Export to markdown | +| `nl` | Normal | Return to last workspace | +| `nu` | Normal | Iterate next list type | +| `np` | Normal | Iterate previous list type | + +### LeetCode + +| Keybinding | Mode | Description | +| ------------ | ------ | ------------------------ | +| `ll` | Normal | Open LeetCode | +| `ld` | Normal | LeetCode daily challenge | +| `lr` | Normal | LeetCode random problem | +| `ls` | Normal | Submit LeetCode solution | +| `lt` | Normal | Test LeetCode solution | diff --git a/lua/custom/plugin_keymaps.lua b/lua/custom/plugin_keymaps.lua new file mode 100644 index 00000000..9de25bf0 --- /dev/null +++ b/lua/custom/plugin_keymaps.lua @@ -0,0 +1,270 @@ +--[[ + Plugin-specific keymaps configuration + + This file contains all the plugin-specific keybindings, + organized by plugin for better readability and maintenance. +]] + +local M = {} + +-- Initialize plugin keymaps +function M.setup() + -- Ensure vim is available in this scope + local vim = vim or _G.vim or require('vim') + + -- 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 + + -- Check if which-key is available + local which_key_ok, wk = pcall(require, "which-key") + if not which_key_ok then + vim.notify("Which-key not found, keybindings will be set without groups", vim.log.levels.WARN) + end + + -------------------------------------------------- + -- TELESCOPE + -------------------------------------------------- + local telescope_builtin_ok, builtin = pcall(require, "telescope.builtin") + if telescope_builtin_ok then + if which_key_ok then + wk.add({ + { "f", group = "Find/Files" }, + { "ff", function() builtin.find_files() end, desc = "Find files" }, + { "fg", function() builtin.live_grep() end, desc = "Live grep" }, + { "fb", function() builtin.buffers() end, desc = "Find buffers" }, + { "fh", function() builtin.help_tags() end, desc = "Help tags" }, + { "fr", function() builtin.oldfiles() end, desc = "Recent files" }, + { "fc", function() builtin.grep_string() end, desc = "Grep current string" }, + { "fk", function() builtin.keymaps() end, desc = "Find keymaps" }, + { "fd", function() builtin.diagnostics() end, desc = "Search diagnostics" }, + { "fw", function() builtin.current_buffer_fuzzy_find() end, desc = "Search current buffer" }, + }) + + wk.add({ + { "fg", group = "Git Search" }, + { "fgc", function() builtin.git_commits() end, desc = "Git commits" }, + { "fgb", function() builtin.git_branches() end, desc = "Git branches" }, + { "fgs", function() builtin.git_status() end, desc = "Git status" }, + { "fgt", function() builtin.git_stash() end, desc = "Git stashes" }, + }) + + wk.add({ + { "", function() builtin.buffers() end, desc = "Find buffers (Telescope)" }, + }) + else + map("n", "ff", function() builtin.find_files() end, { desc = "Find files" }) + map("n", "fg", function() builtin.live_grep() end, { desc = "Live grep" }) + map("n", "fb", function() builtin.buffers() end, { desc = "Find buffers" }) + map("n", "fh", function() builtin.help_tags() end, { desc = "Help tags" }) + map("n", "fr", function() builtin.oldfiles() end, { desc = "Recent files" }) + map("n", "fc", function() builtin.grep_string() end, { desc = "Grep current string" }) + map("n", "fk", function() builtin.keymaps() end, { desc = "Find keymaps" }) + map("n", "fd", function() builtin.diagnostics() end, { desc = "Search diagnostics" }) + map("n", "fw", function() builtin.current_buffer_fuzzy_find() end, { desc = "Search current buffer" }) + map("n", "fgc", function() builtin.git_commits() end, { desc = "Git commits" }) + map("n", "fgb", function() builtin.git_branches() end, { desc = "Git branches" }) + map("n", "fgs", function() builtin.git_status() end, { desc = "Git status" }) + map("n", "fgt", function() builtin.git_stash() end, { desc = "Git stashes" }) + map("n", "", function() builtin.buffers() end, { desc = "Find buffers (Telescope)" }) + end + end + + -------------------------------------------------- + -- BUFFERLINE + -------------------------------------------------- + local bufferline_commands_ok = pcall(require, 'bufferline') + if bufferline_commands_ok then + if which_key_ok then + wk.add({ + { "b", group = "Buffers" }, + { "bp", "BufferLinePick", desc = "Pick buffer" }, + { "bc", "BufferLinePickClose", desc = "Pick buffer to close" }, + { "bh", "BufferLineCyclePrev", desc = "Previous buffer" }, + { "bl", "BufferLineCycleNext", desc = "Next buffer" }, + { "bH", "BufferLineMovePrev", desc = "Move buffer left" }, + { "bL", "BufferLineMoveNext", desc = "Move buffer right" }, + { "b1", "BufferLineGoToBuffer 1", desc = "Buffer 1" }, + { "b2", "BufferLineGoToBuffer 2", desc = "Buffer 2" }, + { "b3", "BufferLineGoToBuffer 3", desc = "Buffer 3" }, + { "b4", "BufferLineGoToBuffer 4", desc = "Buffer 4" }, + { "b5", "BufferLineGoToBuffer 5", desc = "Buffer 5" }, + { "b6", "BufferLineGoToBuffer 6", desc = "Buffer 6" }, + { "b7", "BufferLineGoToBuffer 7", desc = "Buffer 7" }, + { "b8", "BufferLineGoToBuffer 8", desc = "Buffer 8" }, + { "b9", "BufferLineGoToBuffer 9", desc = "Buffer 9" }, + }) + + local alt_buffer_items = {} + for i = 1, 9 do + table.insert(alt_buffer_items, { + string.format("", i), + string.format("BufferLineGoToBuffer %d", i), + desc = string.format("Buffer %d", i) + }) + end + if #alt_buffer_items > 0 then + wk.add(alt_buffer_items) + end + else + map("n", "bp", "BufferLinePick", { desc = "Pick buffer" }) + map("n", "bc", "BufferLinePickClose", { desc = "Pick buffer to close" }) + map("n", "bh", "BufferLineCyclePrev", { desc = "Previous buffer" }) + map("n", "bl", "BufferLineCycleNext", { desc = "Next buffer" }) + map("n", "bH", "BufferLineMovePrev", { desc = "Move buffer left" }) + map("n", "bL", "BufferLineMoveNext", { desc = "Move buffer right" }) + for i = 1, 9 do + map("n", string.format("b%d", i), string.format("BufferLineGoToBuffer %d", i), { desc = string.format("Buffer %d", i) }) + map("n", string.format("", i), string.format("BufferLineGoToBuffer %d", i), { desc = string.format("Buffer %d", i) }) + end + end + end + + -------------------------------------------------- + -- HARPOON + -------------------------------------------------- + local harpoon_ok, harpoon = pcall(require, "harpoon") + if harpoon_ok then + if which_key_ok then + local harpoon_items = { + { "h", group = "Harpoon" }, + { "ha", function() harpoon:list():add() end, desc = "Add file" }, + { "hm", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, desc = "Toggle menu" }, + } + for i = 1, 9 do + table.insert(harpoon_items, { + string.format("h%d", i), + function() harpoon:list():select(i) end, + desc = string.format("Jump to file %d", i) + }) + end + wk.add(harpoon_items) + + wk.add({ + { "", function() harpoon:list():next() end, desc = "Harpoon next file" }, + { "", function() harpoon:list():prev() end, desc = "Harpoon previous file" }, + }) + else + map("n", "ha", function() harpoon:list():add() end, { desc = "Add file" }) + map("n", "hm", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, { desc = "Toggle menu" }) + for i = 1, 9 do + map("n", string.format("h%d", i), function() harpoon:list():select(i) end, { desc = string.format("Jump to file %d", i) }) + end + map("n", "", function() harpoon:list():next() end, { desc = "Harpoon next file" }) + map("n", "", function() harpoon:list():prev() end, { desc = "Harpoon previous file" }) + end + end + + -------------------------------------------------- + -- GIT (LAZYGIT) + -------------------------------------------------- + local lazygit_commands_ok = pcall(require, 'lazygit') + if lazygit_commands_ok then + if which_key_ok then + wk.add({ + { "g", group = "Git" }, + { "gg", "LazyGit", desc = "Open LazyGit" }, + { "gc", "LazyGitConfig", desc = "LazyGit Config" }, + { "gf", "LazyGitCurrentFile", desc = "LazyGit Current File" }, + { "gb", "LazyGitFilter", desc = "LazyGit Filter" }, + { "gB", "LazyGitFilterCurrentFile", desc = "LazyGit Filter Current File" }, + }) + else + map('n', 'gg', 'LazyGit', { desc = 'Open LazyGit' }) + map('n', 'gc', 'LazyGitConfig', { desc = 'LazyGit Config' }) + map('n', 'gf', 'LazyGitCurrentFile', { desc = 'LazyGit Current File' }) + map('n', 'gb', 'LazyGitFilter', { desc = 'LazyGit Filter' }) + map('n', 'gB', 'LazyGitFilterCurrentFile', { desc = 'LazyGit Filter Current File' }) + end + end + + -------------------------------------------------- + -- COMMENTING + -------------------------------------------------- + -- Comment.nvim and other commenting tools are already mapped through their setup + + -------------------------------------------------- + -- COPILOT CHAT + -------------------------------------------------- + local copilot_chat_ok = pcall(require, 'CopilotChat') + if copilot_chat_ok then + if which_key_ok then + -- Normal mode commands + wk.add({ + { "c", group = "Copilot" }, + { "cc", "CopilotChat", desc = "Open Chat" }, + { "ce", "CopilotChatExplain", desc = "Explain Code" }, + { "cf", "CopilotChatFixCode", desc = "Fix Code" }, + { "co", "CopilotChatOptimize", desc = "Optimize Code" }, + { "cd", "CopilotChatDocumentation", desc = "Generate Documentation" }, + { "ct", "CopilotChatTests", desc = "Generate Tests" }, + { "cb", "CopilotChatBestPractices", desc = "Check Best Practices" }, + { "cr", "CopilotChatRefactor", desc = "Refactor Code" }, + { "cs", "CopilotChatSummarize", desc = "Summarize Code" }, + { "ch", "CopilotChatHelp", desc = "Copilot Chat Help" }, + }) + + -- Visual mode commands + wk.add({ + { "c", group = "Copilot", mode = "v" }, + { "ce", ":CopilotChatExplain", desc = "Explain Selected Code", mode = "v" }, + { "cf", ":CopilotChatFixCode", desc = "Fix Selected Code", mode = "v" }, + { "co", ":CopilotChatOptimize", desc = "Optimize Selected Code", mode = "v" }, + { "cd", ":CopilotChatDocumentation", desc = "Document Selected Code", mode = "v" }, + { "ct", ":CopilotChatTests", desc = "Generate Tests for Selection", mode = "v" }, + { "cr", ":CopilotChatRefactor", desc = "Refactor Selected Code", mode = "v" }, + { "cs", ":CopilotChatSummarize", desc = "Summarize Selected Code", mode = "v" }, + }) + else + map("n", "cc", "CopilotChat", { desc = "Open Chat" }) + map("n", "ce", "CopilotChatExplain", { desc = "Explain Code" }) + map("n", "cf", "CopilotChatFixCode", { desc = "Fix Code" }) + map("n", "co", "CopilotChatOptimize", { desc = "Optimize Code" }) + map("n", "cd", "CopilotChatDocumentation", { desc = "Generate Documentation" }) + map("n", "ct", "CopilotChatTests", { desc = "Generate Tests" }) + map("n", "cb", "CopilotChatBestPractices", { desc = "Check Best Practices" }) + map("n", "cr", "CopilotChatRefactor", { desc = "Refactor Code" }) + map("n", "cs", "CopilotChatSummarize", { desc = "Summarize Code" }) + map("n", "ch", "CopilotChatHelp", { desc = "Copilot Chat Help" }) + + map("v", "ce", ":CopilotChatExplain", { desc = "Explain Selected Code" }) + map("v", "cf", ":CopilotChatFixCode", { desc = "Fix Selected Code" }) + map("v", "co", ":CopilotChatOptimize", { desc = "Optimize Selected Code" }) + map("v", "cd", ":CopilotChatDocumentation", { desc = "Document Selected Code" }) + map("v", "ct", ":CopilotChatTests", { desc = "Generate Tests for Selection" }) + map("v", "cr", ":CopilotChatRefactor", { desc = "Refactor Selected Code" }) + map("v", "cs", ":CopilotChatSummarize", { desc = "Summarize Selected Code" }) + end + end + + -------------------------------------------------- + -- LEETCODE + -------------------------------------------------- + local leetcode_ok = pcall(require, 'leetcode') + if leetcode_ok then + if which_key_ok then + wk.add({ + { "l", group = "LeetCode" }, + { "ll", "Leet", desc = "Open LeetCode" }, + { "ld", "Leet daily", desc = "LeetCode daily challenge" }, + { "lr", "Leet random", desc = "LeetCode random problem" }, + { "ls", "Leet submit", desc = "Submit LeetCode solution" }, + { "la", "Leet tabs", desc = "Switch tab" }, + }) + else + map('n', 'll', 'Leet', { desc = 'Open LeetCode' }) + map('n', 'ld', 'Leet daily', { desc = 'LeetCode daily challenge' }) + map('n', 'lr', 'Leet random', { desc = 'LeetCode random problem' }) + map('n', 'ls', 'Leet submit', { desc = 'Submit LeetCode solution' }) + map('n', 'la', 'Leet tabs', { desc = 'Switch tab' }) + end + end + + return M +end + +return M diff --git a/lua/custom/plugins/copilot-chat.lua b/lua/custom/plugins/copilot-chat.lua index ffe78f4a..6dffd880 100644 --- a/lua/custom/plugins/copilot-chat.lua +++ b/lua/custom/plugins/copilot-chat.lua @@ -1,192 +1,287 @@ --- filepath: /home/kali/.config/nvim/lua/custom/plugins/copilot-chat.lua --- GitHub Copilot Chat configuration --- An advanced setup for Copilot Chat in Neovim +--gitHub Copilot Chat configuration - Latest v3+ setup +-- Comprehensive configuration with all features and working keymaps -- https://github.com/CopilotC-Nvim/CopilotChat.nvim --- Declare vim as global -local vim = vim - return { "CopilotC-Nvim/CopilotChat.nvim", - branch = "main", -- Ensure we're using the stable main branch dependencies = { - -- Dependencies for CopilotChat - { "github/copilot.vim" }, -- The base Copilot plugin - { "nvim-lua/plenary.nvim" }, -- Common Lua functions - { "nvim-telescope/telescope.nvim" }, -- For nice UI integration - { "nvim-tree/nvim-web-devicons" }, -- Icons for enhanced UI + { "github/copilot.vim" }, -- or zbirenbaum/copilot.lua + { "nvim-lua/plenary.nvim", branch = "master" }, -- for curl, log and async functions }, - -- Load after GitHub Copilot and when a file is opened - event = { "VeryLazy" }, + build = "make tiktoken", -- Only on MacOS or Linux + event = "VeryLazy", config = function() local chat = require("CopilotChat") local select = require("CopilotChat.select") - -- Configure the plugin with advanced settings + -- Setup CopilotChat with comprehensive configuration chat.setup({ - -- Show Copilot Chat window border + -- Model configuration + model = 'gpt-4.1', -- Default model to use, see ':CopilotChatModels' for available models + agent = 'copilot', -- Default agent to use, see ':CopilotChatAgents' for available agents + context = nil, -- Default context or array of contexts to use + + -- Temperature for GPT responses (0.1 = more focused, 1.0 = more creative) + temperature = 0.1, + + -- Window configuration window = { - border = "rounded", -- Make the window look nice - width = 80, -- Default width - height = 20, -- Default height - title = { - name = "Copilot Chat", -- Custom title - alignment = "center", -- Center the title - }, + layout = 'vertical', -- 'vertical', 'horizontal', 'float', 'replace' + width = 0.5, -- fractional width of parent + height = 0.5, -- fractional height of parent + -- Options for floating windows + relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse' + border = 'rounded', -- 'none', 'single', 'double', 'rounded', 'solid', 'shadow' + title = 'Copilot Chat', + footer = nil, + zindex = 1, }, - -- File context features - context = { - -- Include 5 lines above and below the cursor for context - cursor_context = 5, - - -- Include the entire selection when using visual mode - selection_context = true, - - -- Show context-aware commit history - git_context = true, - }, + -- UI settings + show_help = true, -- Shows help message as virtual lines when waiting for user input + highlight_selection = true, -- Highlight selection in source buffer + highlight_headers = true, -- Highlight headers in chat + auto_follow_cursor = true, -- Auto-follow cursor in chat + auto_insert_mode = false, -- Automatically enter insert mode when opening window + insert_at_end = false, -- Move cursor to end of buffer when inserting text + clear_chat_on_new_prompt = false, -- Clears chat on every new prompt - -- Enable debug (set to true only when troubleshooting) - debug = false, + -- Chat features + chat_autocomplete = true, -- Enable chat autocompletion - -- Enable syntax highlighting in response - syntax_highlighting = true, + -- Default selection (uses visual selection or falls back to buffer) + selection = function(source) + return select.visual(source) or select.buffer(source) + end, - -- Enable auto-sizing of response window - auto_size = true, - - -- Define prompts that can be used in commands + -- Custom prompts for various coding tasks prompts = { - -- Default prompts + -- Code explanation Explain = { - prompt = "Explain how the following code works in detail:\n```$filetype\n$selection\n```", + prompt = 'Write an explanation for the selected code as paragraphs of text.', + system_prompt = 'COPILOT_EXPLAIN', }, - FixCode = { - prompt = "Fix the following code. Provide the corrected version and explanations for the fixes:\n```$filetype\n$selection\n```", + + -- Code review + Review = { + prompt = 'Review the selected code.', + system_prompt = 'COPILOT_REVIEW', }, + + -- Bug fixes + Fix = { + prompt = 'There is a problem in this code. Identify the issues and rewrite the code with fixes. Explain what was wrong and how your changes address the problems.', + }, + + -- Code optimization Optimize = { - prompt = "Optimize the following code. Provide the optimized version and explain the improvements:\n```$filetype\n$selection\n```", + prompt = 'Optimize the selected code to improve performance and readability. Explain your optimization strategy and the benefits of your changes.', }, - -- Advanced prompts - Documentation = { - prompt = "Generate comprehensive documentation for this code:\n```$filetype\n$selection\n```\nInclude descriptions of parameters, return values, exceptions, and provide usage examples.", - }, - BestPractices = { - prompt = "Review this code for best practices and suggest improvements:\n```$filetype\n$selection\n```", + + -- Documentation generation + Docs = { + prompt = 'Please add documentation comments to the selected code.', }, + + -- Test generation Tests = { - prompt = "Generate unit tests for the following code:\n```$filetype\n$selection\n```", + prompt = 'Please generate tests for my code.', }, - -- Context-aware code generation - Implement = { - prompt = "Implement the following functionality: $input\nMake it work with the following context:\n```$filetype\n$selection\n```", - strategy = "quick_fix", -- Use the quick fix strategy for implementation + + -- Commit message generation + Commit = { + prompt = 'Write commit message for the change with commitizen convention. Keep the title under 50 characters and wrap message at 72 characters. Format as a gitcommit code block.', + context = 'git:staged', }, - RefactorToPattern = { - prompt = "Refactor the following code to use the $input design pattern. Explain the benefits of this refactoring:\n```$filetype\n$selection\n```", + + -- Custom advanced prompts + Refactor = { + prompt = 'Please refactor the following code to improve its structure and readability. Explain the changes you made and why they improve the code.', + }, + + BestPractices = { + prompt = 'Review this code for best practices and suggest improvements. Focus on code quality, maintainability, and adherence to language-specific conventions.', + }, + + Security = { + prompt = 'Analyze this code for potential security vulnerabilities and suggest fixes. Consider common security issues like injection attacks, authentication, authorization, and data validation.', + }, + + Performance = { + prompt = 'Analyze this code for performance issues and suggest optimizations. Consider algorithmic complexity, memory usage, and language-specific performance patterns.', + }, + + -- Context-aware prompts + ImplementFeature = { + prompt = 'Based on the selected code, implement the following feature: ', + mapping = 'cif', + description = 'Implement a new feature based on existing code', + }, + + ExplainError = { + prompt = 'Explain this error and provide a solution: ', + mapping = 'cee', + description = 'Explain error and provide solution', + }, + }, + + -- Custom mappings for chat buffer + mappings = { + complete = { + insert = '', + }, + close = { + normal = 'q', + insert = '', + }, + reset = { + normal = '', + insert = '', + }, + submit_prompt = { + normal = '', + insert = '', + }, + toggle_sticky = { + normal = 'grr', + }, + clear_stickies = { + normal = 'grx', + }, + accept_diff = { + normal = '', + insert = '', + }, + jump_to_diff = { + normal = 'gj', + }, + quickfix_answers = { + normal = 'gqa', + }, + quickfix_diffs = { + normal = 'gqd', + }, + yank_diff = { + normal = 'gy', + register = '"', + }, + show_diff = { + normal = 'gd', + full_diff = false, + }, + show_info = { + normal = 'gi', + }, + show_context = { + normal = 'gc', + }, + show_help = { + normal = 'gh', }, }, }) - -- Add custom keymaps for the chat buffer - vim.api.nvim_create_autocmd("FileType", { - pattern = "copilot-chat", - callback = function() - local buf = vim.api.nvim_get_current_buf() - - -- Close window with 'q' - vim.keymap.set("n", "q", function() - vim.cmd("close") - end, { buffer = buf, silent = true }) - - -- Reset chat with Ctrl+L - vim.keymap.set("n", "", function() - chat.reset() - end, { buffer = buf, silent = true }) - - -- -- Submit prompt with Enter in insert mode - -- vim.keymap.set("i", "", function() - -- -- require("CopilotChat").submit_prompt() - -- chat.submit_prompt() - -- end, { buffer = buf, silent = true }) - - -- -- Submit prompt with Enter in normal mode - -- vim.keymap.set("n", "", function() - -- require("CopilotChat").submit_prompt() - -- end, { buffer = buf, silent = true }) - - -- Show diff with Ctrl+D - vim.keymap.set("n", "", function() - require("CopilotChat").show_diff() - end, { buffer = buf, silent = true }) - - -- Accept diff with Ctrl+Y - vim.keymap.set("n", "", function() - require("CopilotChat").accept_diff() - end, { buffer = buf, silent = true }) - end - }) + -- Global keymaps for CopilotChat + -- Core commands + vim.keymap.set("n", "cc", function() chat.toggle() end, { desc = "Toggle Copilot Chat" }) + vim.keymap.set("n", "co", function() chat.open() end, { desc = "Open Copilot Chat" }) + vim.keymap.set("n", "cx", function() chat.close() end, { desc = "Close Copilot Chat" }) + vim.keymap.set("n", "cr", function() chat.reset() end, { desc = "Reset Copilot Chat" }) + vim.keymap.set("n", "cs", function() chat.stop() end, { desc = "Stop Copilot Chat" }) - -- Set up key bindings - vim.keymap.set("n", "cc", "CopilotChat", { desc = "Copilot Chat" }) - vim.keymap.set("n", "ce", "CopilotChatExplain", { desc = "Explain Code" }) - vim.keymap.set("n", "cf", "CopilotChatFixCode", { desc = "Fix Code" }) - vim.keymap.set("n", "co", "CopilotChatOptimize", { desc = "Optimize Code" }) - vim.keymap.set("n", "cd", "CopilotChatDocumentation", { desc = "Generate Documentation" }) - vim.keymap.set("n", "ct", "CopilotChatTests", { desc = "Generate Tests" }) - vim.keymap.set("n", "cb", "CopilotChatBestPractices", { desc = "Check Best Practices" }) + -- Prompt-based commands - these work with current selection + vim.keymap.set({"n", "v"}, "cce", "CopilotChatExplain", { desc = "Explain code" }) + vim.keymap.set({"n", "v"}, "ccr", "CopilotChatReview", { desc = "Review code" }) + vim.keymap.set({"n", "v"}, "ccf", "CopilotChatFix", { desc = "Fix code" }) + vim.keymap.set({"n", "v"}, "cco", "CopilotChatOptimize", { desc = "Optimize code" }) + vim.keymap.set({"n", "v"}, "ccd", "CopilotChatDocs", { desc = "Generate docs" }) + vim.keymap.set({"n", "v"}, "cct", "CopilotChatTests", { desc = "Generate tests" }) + vim.keymap.set({"n", "v"}, "ccrf", "CopilotChatRefactor", { desc = "Refactor code" }) + vim.keymap.set({"n", "v"}, "ccb", "CopilotChatBestPractices", { desc = "Best practices" }) + vim.keymap.set({"n", "v"}, "ccs", "CopilotChatSecurity", { desc = "Security review" }) + vim.keymap.set({"n", "v"}, "ccp", "CopilotChatPerformance", { desc = "Performance review" }) - -- Visual mode mappings for selected code - vim.keymap.set("v", "ce", ":CopilotChatExplain", { desc = "Explain Selected Code" }) - vim.keymap.set("v", "cf", ":CopilotChatFixCode", { desc = "Fix Selected Code" }) - vim.keymap.set("v", "co", ":CopilotChatOptimize", { desc = "Optimize Selected Code" }) - vim.keymap.set("v", "cd", ":CopilotChatDocumentation", { desc = "Document Selected Code" }) - vim.keymap.set("v", "ct", ":CopilotChatTests", { desc = "Generate Tests for Selected Code" }) + -- Git integration + vim.keymap.set("n", "ccg", "CopilotChatCommit", { desc = "Generate commit message" }) - -- Create a custom input command with implementation suggestions - vim.keymap.set("v", "ci", function() - vim.ui.input({ prompt = "What would you like to implement? " }, function(input) - if input then - select.selection() - chat.ask("Implement: " .. input) + -- Advanced features + vim.keymap.set("n", "ccm", "CopilotChatModels", { desc = "Select model" }) + vim.keymap.set("n", "cca", "CopilotChatAgents", { desc = "Select agent" }) + vim.keymap.set("n", "ccp", "CopilotChatPrompts", { desc = "Select prompt" }) + + -- Chat history + vim.keymap.set("n", "ccl", function() + vim.ui.input({ prompt = "Load chat (name): " }, function(name) + if name then + chat.load(name) end end) - end, { desc = "Implement Functionality" }) + end, { desc = "Load chat history" }) - -- Add quick access to buffer context - vim.keymap.set("n", "cb", function() - chat.ask("What does this code do? Consider the full context of the file.", { - selection = select.buffer, - }) - end, { desc = "Explain Buffer" }) - - -- Refactor the current selection to use a specific design pattern - vim.keymap.set("v", "cr", function() - vim.ui.input({ prompt = "Which design pattern to refactor to? " }, function(input) - if input then - select.selection() - chat.ask("RefactorToPattern: " .. input) + vim.keymap.set("n", "ccS", function() + vim.ui.input({ prompt = "Save chat (name): " }, function(name) + if name then + chat.save(name) end end) - end, { desc = "Refactor to Design Pattern" }) + end, { desc = "Save chat history" }) - -- Toggle inline chat for quick questions about the current line - vim.keymap.set("n", "cl", function() - -- Use chat.ask with a line selector instead of separate select.line() call - chat.ask("What does this line of code do?", { - selection = select.line, -- Pass the function reference, not the function call - }) - end, { desc = "Chat About Current Line" }) - - -- Open Copilot Chat with a custom prompt - vim.keymap.set("n", "cp", function() + -- Custom prompts with input + vim.keymap.set({"n", "v"}, "cci", function() vim.ui.input({ prompt = "Ask Copilot: " }, function(input) if input then chat.ask(input) end end) - end, { desc = "Ask Copilot" }) + end, { desc = "Ask custom question" }) + + -- Context-specific commands + vim.keymap.set("n", "ccbf", function() + chat.ask("Explain what this file does and its main purpose.", { + selection = select.buffer, + }) + end, { desc = "Explain buffer" }) + + vim.keymap.set("n", "ccgd", function() + chat.ask("Explain these git changes.", { + context = "git", + }) + end, { desc = "Explain git diff" }) + + -- Line-specific command + vim.keymap.set("n", "ccl", function() + chat.ask("Explain this line of code in detail.", { + selection = select.line, + }) + end, { desc = "Explain current line" }) + + -- Quick actions for selected text + vim.keymap.set("v", "cq", function() + chat.ask("Quick question about this code: " .. vim.fn.input("Question: "), { + selection = select.visual, + }) + end, { desc = "Quick question about selection" }) + + -- Buffer auto-commands for chat window + vim.api.nvim_create_autocmd("BufEnter", { + pattern = "copilot-*", + callback = function() + -- Set buffer-local options for better UX + vim.opt_local.relativenumber = false + vim.opt_local.number = false + vim.opt_local.cursorline = false + vim.opt_local.signcolumn = "no" + vim.opt_local.foldcolumn = "0" + end, + }) + + -- Notification on chat completion + vim.api.nvim_create_autocmd("User", { + pattern = "CopilotChatComplete", + callback = function() + vim.notify("Copilot Chat response complete", vim.log.levels.INFO) + end, + }) end, } diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 718fea53..f5b9b5a5 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -16,4 +16,6 @@ return { { import = "custom.plugins.leetcode" }, -- { import = "custom.plugins.telescope_fix" }, { import = "custom.plugins.catppuccin" }, + { import = "custom.plugins.neorg" }, + { import = "custom.plugins.which_key_integration" }, -- Load which-key integration } diff --git a/lua/custom/plugins/jdtls_config.lua b/lua/custom/plugins/jdtls_config.lua new file mode 100644 index 00000000..d1bd6d5c --- /dev/null +++ b/lua/custom/plugins/jdtls_config.lua @@ -0,0 +1,52 @@ +--[[ + JDTLS Configuration + + This file configures the Java Development Tools Language Server (jdtls) + to fix deprecation warnings and JVM restrictions. +]] + +return { + -- Override the default jdtls setup + { + "neovim/nvim-lspconfig", + opts = { + -- Configure jdtls with the necessary JVM arguments to fix warnings + setup = { + jdtls = function(_, opts) + -- Get existing Java arguments or initialize an empty table + local java_args = opts.cmd or {} + + -- Add the necessary JVM arguments to fix the deprecation warnings + local fixed_java_args = { + -- Enable unrestricted access to JDK internal API + "--enable-native-access=ALL-UNNAMED", + -- Explicitly allow these modules to eliminate warnings + "--add-modules=jdk.incubator.vector", + -- Suppress deprecation warnings + "-Dsun.misc.Unsafe.allowDeprecation=true", + } + + -- Find the java command index in the cmd array + local java_cmd_index = 1 + for i, arg in ipairs(java_args) do + if arg:match("java$") then + java_cmd_index = i + break + end + end + + -- Insert our arguments after the java command + for i, arg in ipairs(fixed_java_args) do + table.insert(java_args, java_cmd_index + i, arg) + end + + -- Update the command + opts.cmd = java_args + + -- Return false to let the default handler continue + return false + end, + }, + }, + } +} diff --git a/lua/custom/plugins/leetcode.lua b/lua/custom/plugins/leetcode.lua index ed7eef6b..23380b1f 100644 --- a/lua/custom/plugins/leetcode.lua +++ b/lua/custom/plugins/leetcode.lua @@ -3,91 +3,91 @@ -- https://github.com/kawre/leetcode.nvim return { - "kawre/leetcode.nvim", + 'kawre/leetcode.nvim', dependencies = { - "nvim-telescope/telescope.nvim", - "nvim-lua/plenary.nvim", - "MunifTanjim/nui.nvim", - "nvim-tree/nvim-web-devicons", -- optional but recommended - "nvim-treesitter/nvim-treesitter" -- make sure treesitter is a direct dependency + 'nvim-telescope/telescope.nvim', + 'nvim-lua/plenary.nvim', + 'MunifTanjim/nui.nvim', + 'nvim-tree/nvim-web-devicons', -- optional but recommended + 'nvim-treesitter/nvim-treesitter', -- make sure treesitter is a direct dependency }, build = function() -- Make sure the HTML parser is installed for treesitter - require("nvim-treesitter.install").ensure_installed("html") + require('nvim-treesitter.install').ensure_installed 'html' end, config = function() - require("leetcode").setup({ + require('leetcode').setup { -- Default language for solving problems - lang = "python3", -- you can change this to your preferred language - + lang = 'python3', -- you can change this to your preferred language + -- Storage directories storage = { - home = vim.fn.stdpath("data") .. "/leetcode", - cache = vim.fn.stdpath("cache") .. "/leetcode", + home = vim.fn.stdpath 'data' .. '/leetcode', + cache = vim.fn.stdpath 'cache' .. '/leetcode', }, - + -- Console settings console = { open_on_runcode = true, - dir = "row", -- "row" or "col" for horizontal or vertical split + dir = 'row', -- "row" or "col" for horizontal or vertical split size = { - width = "90%", - height = "75%", + width = '90%', + height = '75%', }, result = { - size = "60%", + size = '60%', }, testcase = { virt_text = true, - size = "40%", + size = '40%', }, }, - + -- Description panel settings description = { - position = "left", -- "left" or "right" - width = "40%", + position = 'left', -- "left" or "right" + width = '40%', show_stats = true, -- show problem stats in description panel }, - + -- You can choose either telescope or fzf-lua picker = { - provider = "telescope", -- set to "fzf-lua" if you prefer that + provider = 'telescope', -- set to "fzf-lua" if you prefer that }, - + -- Default keybindings - these won't conflict with your existing mappings -- as they only activate within LeetCode buffers keys = { - toggle = { "q" }, - confirm = { "" }, - - reset_testcases = "r", - use_testcase = "U", - focus_testcases = "H", - focus_result = "L", + toggle = { 'q' }, + confirm = { '' }, + + reset_testcases = 'r', + use_testcase = 'U', + focus_testcases = 'H', + focus_result = 'L', }, - + -- Code injection settings - adds useful imports automatically injector = { - ["cpp"] = { - before = { "#include ", "using namespace std;" }, + ['cpp'] = { + before = { '#include ', 'using namespace std;' }, }, - ["java"] = { - before = "import java.util.*;", + ['java'] = { + before = 'import java.util.*;', }, - ["python3"] = { + ['python3'] = { before = true, -- use default imports }, }, - + -- Enable logging logging = true, - + -- Non-standalone mode (false means it won't interfere with your normal workflow) plugins = { non_standalone = false, }, - }) + } end, - cmd = "Leet", -- lazy-load on command + cmd = 'Leet', -- lazy-load on command } diff --git a/lua/custom/plugins/neorg.lua b/lua/custom/plugins/neorg.lua new file mode 100644 index 00000000..5ecae8dc --- /dev/null +++ b/lua/custom/plugins/neorg.lua @@ -0,0 +1,185 @@ +-- Neorg - An organized future for Neovim +-- https://github.com/nvim-neorg/neorg +-- +-- Documentation: https://github.com/nvim-neorg/neorg/wiki +-- Modules reference: https://github.com/nvim-neorg/neorg/wiki/User-Modules-Reference + +return { + "nvim-neorg/neorg", + lazy = false, -- Disable lazy loading to ensure proper initialization + -- Pin the version for stability - you can update when ready + version = "*", -- Use the latest stable version + dependencies = { + "nvim-lua/plenary.nvim", -- Already should be installed in your config + "nvim-treesitter/nvim-treesitter", + "nvim-treesitter/nvim-treesitter-textobjects", + "hrsh7th/nvim-cmp", -- Proper repository path for nvim-cmp + }, + build = ":Neorg sync-parsers", -- This will install the Neorg treesitter parser + config = function() + require("neorg").setup { + load = { + -- Load the core modules that provide basic functionality + ["core.defaults"] = {}, -- Loads default modules + + -- Essential modules for a good experience + ["core.concealer"] = { + config = { + icon_preset = "diamond", -- Icon style: basic, diamond, varied + icons = { + -- Custom icons for improved visual appearance + heading = { + icons = { "◉", "○", "✸", "✿" }, -- Cycle through these for heading levels + }, + -- Keep default values for other icons + todo = { + pending = { icon = "" }, -- Keep the default + }, + }, + folds = true, -- Enable folding of nested content + performance = { + conceal_modifier_pre = 200, -- Optimized conceal performance + conceal_modifier_post = 300, + concealer_weight_implies_priority = true, + }, + }, + }, + + -- For managing directories of .norg files - required for many features + ["core.dirman"] = { + config = { + workspaces = { + notes = "~/notes", -- General notes + work = "~/work/notes", -- Work-related notes + personal = "~/personal/notes", -- Personal notes + projects = "~/projects/notes", -- Project-specific notes + }, + default_workspace = "notes", + index = "index.norg", -- Default index file to look for + }, + }, + + -- Enhance completion capabilities - integrates with your existing completion + ["core.completion"] = { + config = { + engine = "nvim-cmp", -- Use nvim-cmp for completion + name = "neorg", -- Source name for nvim-cmp + -- Customize completion behavior + snippet_engine = nil, -- Will use your configured snippet engine + trigger_on_carriage_return = true, -- Trigger completion when pressing Enter + }, + }, + + -- Export your Neorg files to other formats + ["core.export"] = {}, -- Base export module + ["core.export.markdown"] = { + config = { + extensions = "all", -- Export all extensions + versioning = { + -- Add version information to exported files + enabled = true, + -- Pattern: {year}{month}{day}{hour}{min}{sec}_filename.md + pattern = "%Y%m%d%H%M%S_{name}.md", + }, + }, + }, + + -- For a nicer table of contents + ["core.qol.toc"] = { + config = { + toc_title = "Table of Contents", -- Title of the TOC + close_after_use = true, -- Close TOC after jumping to a heading + default_level = 4, -- Show headings up to this level + toc_position = "right", -- Position of the TOC window + }, + }, + + -- For taking journal notes + ["core.journal"] = { + config = { + strategy = "flat", -- "flat" for single files, "nested" for year/month/day structure + workspace = "notes", -- Use the notes workspace for journal entries + journal_folder = "journal", -- Store journal entries in this subfolder + use_template = false, -- Whether to use a template for new entries + template_name = nil, -- Optional template name if use_template is true + zipper_indicator = false, -- Show indicators for fast navigation + }, + }, + + -- Summary generation for notes (new module) + ["core.summary"] = {}, + + -- Enhanced UI presentation mode + ["core.presenter"] = { + config = { + zen_mode = "zen-mode", -- Zen mode plugin to use (if installed) + slide_count = true, -- Show slide count in presenter mode + } + }, + + -- Enhance keybinds with custom modes + ["core.keybinds"] = { + -- This config is crucial for avoiding keybinding conflicts + config = { + -- All Neorg keybindings are only active inside .norg files + -- They won't affect your existing keymaps in other file types + default_keybinds = true, + neorg_leader = "n", -- Use n as the Neorg prefix + + -- Custom keybinds organized by category + hook = function(keybinds) + -- Navigation keybinds + keybinds.map("norg", "n", "nj", "Neorg journal today", + { desc = "Open today's journal" }) + keybinds.map("norg", "n", "nyt", "Neorg journal yesterday", + { desc = "Open yesterday's journal" }) + keybinds.map("norg", "n", "ntm", "Neorg journal tomorrow", + { desc = "Open tomorrow's journal" }) + + -- Workspace management + keybinds.map("norg", "n", "nw", "Neorg workspace", + { desc = "Open workspace selector" }) + keybinds.map("norg", "n", "nn", "Neorg workspace notes", + { desc = "Switch to notes workspace" }) + keybinds.map("norg", "n", "nwp", "Neorg workspace personal", + { desc = "Switch to personal workspace" }) + + -- Document manipulation + keybinds.map("norg", "n", "ntt", "Neorg toc", + { desc = "Generate table of contents" }) + keybinds.map("norg", "n", "ni", "Neorg inject-metadata", + { desc = "Inject metadata" }) + keybinds.map("norg", "n", "nm", "Neorg update-metadata", + { desc = "Update metadata" }) + + -- Export commands + keybinds.map("norg", "n", "nem", "Neorg export to-markdown", + { desc = "Export to Markdown" }) + + -- Toggle concealer + keybinds.map("norg", "n", "nc", "Neorg toggle-concealer", + { desc = "Toggle concealer" }) + + -- Return to last workspace + keybinds.map("norg", "n", "nl", "Neorg return", + { desc = "Return to last workspace" }) + + -- Advanced keybinds for list manipulation + keybinds.map_event("norg", "n", "nu", "core.itero.next-iteration", + { desc = "Iterate next" }) + keybinds.map_event("norg", "n", "np", "core.itero.previous-iteration", + { desc = "Iterate previous" }) + end, + }, + }, + + -- Module for better list handling + ["core.itero"] = {}, + + -- UI improvements for better look and feel + ["core.ui"] = {}, + ["core.ui.calendar"] = {}, -- Calendar view for journal navigation + }, + } + end, +} diff --git a/lua/custom/plugins/neorg_guide.md b/lua/custom/plugins/neorg_guide.md new file mode 100644 index 00000000..242c7e52 --- /dev/null +++ b/lua/custom/plugins/neorg_guide.md @@ -0,0 +1,310 @@ +# Neorg Guide: Organized Note-Taking for Neovim + +Neorg is a powerful tool for structured note-taking, project and task management, time tracking, and more, all within Neovim. This guide will help you get started with the basics and highlight advanced features. + +## Getting Started + +To start using Neorg: + +1. Make sure `luarocks` is installed on your system: + + ```bash + sudo pacman -S luarocks + # Or using yay if it's not in the main repos + # yay -S luarocks + ``` + +2. Create your first Neorg file: + + ``` + :e notes.norg + ``` + +3. Initialize your workspace directories if they don't exist: + ```bash + mkdir -p ~/notes ~/work/notes ~/personal/notes ~/projects/notes + ``` + +## Key Concepts + +### Workspaces + +Workspaces are directories where your Neorg files are stored. Your configuration includes: + +- `notes`: Your general notes (~/notes) +- `work`: Work-related notes (~/work/notes) +- `personal`: Personal notes (~/personal/notes) +- `projects`: Project-specific notes (~/projects/notes) + +### Keybinding Structure + +All Neorg keybindings start with `n` (usually `\n` or `n` depending on your leader key) to avoid conflicts with your existing bindings. + +#### Navigation & Workspaces + +- `nw` - Open workspace selector +- `nn` - Switch to notes workspace +- `nwp` - Switch to personal workspace +- `nl` - Return to last workspace + +#### Journal + +- `nj` - Open today's journal +- `nyt` - Open yesterday's journal +- `ntm` - Open tomorrow's journal +- `nwd` - Go to day view in journal +- `nwm` - Go to month view in journal + +#### Document Manipulation + +- `ntt` - Generate table of contents +- `ni` - Inject metadata +- `nm` - Update metadata +- `nc` - Toggle concealer +- `nil` - Insert link +- `nid` - Insert date + +#### Export Commands + +- `nem` - Export to Markdown + +#### Advanced List Manipulation + +- `nu` - Iterate to next list type (cycle through bullet types/numbers) +- `np` - Iterate to previous list type + +### Basic Syntax + +```norg +* Heading 1 +** Heading 2 +*** Heading 3 + +- Unordered list + - Nested item + - More nesting + +1. Ordered list +2. Second item + +~ Definition list + Term 1 :: Definition 1 + Term 2 :: Definition 2 +~ + +( ) Undone task +(x) Completed task +(?) Pending task +(!) Important task +(-) Pending task +(=) Recurring task +(+) On hold task + +`inline code` + +@code lua +print("Hello from Neorg!") +@end + +{https://github.com/nvim-neorg/neorg}[Link to Neorg] + +> This is a quote +> It can span multiple lines + +$ E = mc^2 $ -- Inline math + +@math +f(x) = \int_{-\infty}^\infty + \hat f(\xi)\,e^{2 \pi i \xi x} + \,d\xi +@end +``` + +## Command Reference + +### Common Commands + +| Command | Description | +| --------------------------- | ------------------------------- | +| `:Neorg workspace notes` | Switch to notes workspace | +| `:Neorg journal today` | Open today's journal | +| `:Neorg toc` | Generate a table of contents | +| `:Neorg export to-markdown` | Export current file to markdown | +| `:Neorg toggle-concealer` | Toggle the concealer on/off | +| `:Neorg return` | Return to the last workspace | + +### Advanced Commands + +| Command | Description | +| ----------------------------------- | -------------------------------- | +| `:Neorg inject-metadata` | Add metadata to current document | +| `:Neorg update-metadata` | Update document metadata | +| `:Neorg journal template` | Create/edit journal template | +| `:Neorg keybind all` | Show all available keybindings | +| `:Neorg modules list` | List all loaded modules | +| `:Neorg generate-workspace-summary` | Generate workspace summary | + +## Advanced Features + +### Journal Management + +Your journal is configured with a flat structure in the `~/notes/journal` directory: + +``` +:Neorg journal today # Open today's journal +:Neorg journal yesterday # Open yesterday's journal +:Neorg journal tomorrow # Open tomorrow's journal +``` + +Use `nj` for quick access to today's journal. + +### Export Options + +Export to different formats for sharing: + +```vim +:Neorg export to-markdown " Basic markdown export +:Neorg export to-markdown all " Export with all extensions +``` + +The export includes version info with timestamps in the filename format. + +### Table of Contents + +Generate and use a table of contents with `ntt` or `:Neorg toc`. +The TOC is interactive - you can navigate to any section by selecting it. + +### Presenter Mode + +Turn your notes into presentations: + +```vim +:Neorg presenter start " Start presenter mode +``` + +Navigate slides with: + +- `j/k` or arrow keys - Next/previous slide +- `q` - Exit presenter + +## Tips for Best Experience + +> 📌 **Note**: A comprehensive keybinding reference is available in the file: +> `/home/kali/.config/nvim/lua/custom/plugins/neorg_keymaps_reference.md` + +1. **Create workspace directories** before using them: + + ```bash + mkdir -p ~/notes ~/work/notes ~/personal/notes ~/projects/notes + ``` + +2. **Set conceallevel** for a better visual experience: + + ```vim + :set conceallevel=2 + ``` + +3. **Use the journal** for daily notes and tracking with the `nj` shortcut. + +4. **Follow links** by placing cursor on a link and pressing ``. + +5. **Export to other formats** when needed to share your notes with `nem`. + +6. **Use folding** to collapse and expand sections: + + - `za` - Toggle fold under cursor + - `zR` - Open all folds + - `zM` - Close all folds + +7. **Use custom keybindings** to streamline your workflow - all under the `n` prefix. + +8. **Check Neorg health** if you encounter issues: + + ```vim + :checkhealth neorg + ``` + +9. **Use calendar navigation** for journal entries: + + ```vim + :Neorg journal calendar + ``` + + Navigate with arrow keys and press Enter on a date. + +10. **Create summaries** of your notes: + ```vim + :Neorg generate-summary + ``` + +## Advanced Document Structure + +### Metadata + +Add metadata to documents for better organization: + +```norg +@document.meta +title: Project Planning +description: Strategic planning document for Q3 2025 +authors: [your_name] +categories: [planning, strategy] +created: 2025-06-09 +version: 1.0 +@end +``` + +### Cross-Linking + +Create links between your notes: + +```norg +{:my-other-file:}[Link to another file] +{:my-other-file:*some-heading}[Link to specific heading] +{* My Heading}[Link to heading in current file] +``` + +### Advanced Tasks + +Track tasks with metadata: + +```norg +(x) Completed task #project @tag <2025-06-01> +( ) Upcoming task #work @important <2025-06-15> +(!) Critical task with ^high^ priority +``` + +### Code Execution + +Some code blocks can be executed directly from Neorg: + +```norg +@code lua runnable +print("Hello from Neorg!") +@end +``` + +Use `re` to run the code block under your cursor. + +## Customization + +Your Neorg setup is configured with: + +- Diamond icon preset for better visuals +- Custom keybindings under `n` prefix +- Four configured workspaces +- Enhanced journal capabilities + +Refer to the full configuration in `/home/kali/.config/nvim/lua/custom/plugins/neorg.lua` for more details. +:Neorg export to-markdown + +``` + +## Compatibility + +Neorg is designed to work alongside your existing Neovim setup without conflicts. All keymaps are scoped to `.norg` files to avoid conflicts with other plugins. + +## Learning More + +Visit the [Neorg Wiki](https://github.com/nvim-neorg/neorg/wiki) for comprehensive documentation on all modules and features. +``` diff --git a/lua/custom/plugins/neorg_keymaps_reference.md b/lua/custom/plugins/neorg_keymaps_reference.md new file mode 100644 index 00000000..94af1882 --- /dev/null +++ b/lua/custom/plugins/neorg_keymaps_reference.md @@ -0,0 +1,129 @@ +# Neorg Keybindings Reference + +All Neorg keybindings are namespaced under `n` to avoid conflicts with other plugins. These bindings are only active in `.norg` files. + +## 🚀 Getting Started + +To check your Neorg setup, run this command in Neovim: + +```vim +:lua require('custom.utils.neorg_setup_check').check() +``` + +To create your first Neorg file: + +```vim +:e myfile.norg +``` + +To access your notes index: + +```vim +:Neorg workspace notes +``` + +## Navigation & Workspace Management + +| Keybinding | Description | +| ------------- | ---------------------------- | +| `nw` | Open workspace selector | +| `nn` | Switch to notes workspace | +| `nwp` | Switch to personal workspace | +| `nl` | Return to last workspace | + +## Journal + +| Keybinding | Description | +| ------------- | --------------------------- | +| `nj` | Open today's journal | +| `nyt` | Open yesterday's journal | +| `ntm` | Open tomorrow's journal | +| `nwd` | Go to day view in journal | +| `nwm` | Go to month view in journal | + +## Document Structure + +| Keybinding | Description | +| ------------- | -------------------------- | +| `ntt` | Generate table of contents | +| `ni` | Inject metadata | +| `nm` | Update metadata | +| `nc` | Toggle concealer | + +## Content Creation + +| Keybinding | Description | +| ------------- | ----------- | +| `nil` | Insert link | +| `nid` | Insert date | + +## Export + +| Keybinding | Description | +| ------------- | ------------------ | +| `nem` | Export to Markdown | + +## Advanced List Manipulation + +| Keybinding | Description | +| ------------ | ------------------------------- | +| `nu` | Iterate next (cycle list types) | +| `np` | Iterate previous | + +## Default Keybindings + +Additionally, Neorg has many default keybindings that are active in `.norg` files: + +### Navigation + +| Keybinding | Description | +| ---------- | ---------------------------- | +| `` | Follow link under cursor | +| `` | Follow link up | +| `` | Follow link down | +| `` | Follow link previous | +| `` | Follow link next | +| `gO` | Navigate to previous heading | +| `gI` | Navigate to next heading | + +### Lists & Tasks + +| Keybinding | Description | +| ---------- | -------------------------------------- | +| `` | Toggle task status | +| `` | Toggle list type | +| `` | Indent current line (in insert mode) | +| `` | Unindent current line (in insert mode) | + +### Folding (when folding is enabled) + +| Keybinding | Description | +| ---------- | ------------------------ | +| `za` | Toggle fold under cursor | +| `zR` | Open all folds | +| `zM` | Close all folds | + +### Text Objects + +| Keybinding | Description | +| ---------- | -------------- | +| `ah` | Around heading | +| `ih` | Inside heading | +| `al` | Around list | +| `il` | Inside list | + +### Presenter Mode + +| Keybinding | Description | +| ---------- | ------------------- | +| `j`/`k` | Next/previous slide | +| `q` | Exit presenter | + +## Command Reference + +| Command | Description | +| ------------------------- | ------------------------------ | +| `:Neorg keybind all` | Show all available keybindings | +| `:Neorg index` | Go to workspace index file | +| `:Neorg return` | Return to previous location | +| `:Neorg toggle-concealer` | Toggle concealer | diff --git a/lua/custom/plugins/neorg_optimization_summary.md b/lua/custom/plugins/neorg_optimization_summary.md new file mode 100644 index 00000000..b9588d4e --- /dev/null +++ b/lua/custom/plugins/neorg_optimization_summary.md @@ -0,0 +1,82 @@ +# Neorg Configuration Optimization Summary + +## Optimizations Made + +### 1. Enhanced Core Configuration + +- Improved concealer settings with the "diamond" icon preset for better visuals +- Added performance optimizations for the concealer +- Added a new "projects" workspace +- Added index file configuration +- Configured versioning for exports + +### 2. Added New Modules + +- Added `core.summary` module for generating note summaries +- Added `core.presenter` module for presentation mode +- Added `core.itero` module for better list handling +- Added `core.ui.calendar` for calendar navigation in journal + +### 3. Enhanced Keybindings + +- Created namespaced keybindings under `n` +- Added specialized keybindings for common operations: + - Journal management + - Workspace navigation + - Document manipulation + - Export functions + - List manipulation + +### 4. Created Documentation + +- Comprehensive `neorg_guide.md` with detailed usage instructions +- Dedicated `neorg_keymaps_reference.md` for quick reference +- Setup checking tool for troubleshooting + +### 5. Created File Structure + +- Set up workspace directories: + - ~/notes + - ~/work/notes + - ~/personal/notes + - ~/projects/notes +- Created folder structure within notes +- Added index.norg as a starting point + +## How to Use the Optimized Setup + +1. **Check your setup** with the provided utility: + + ```vim + :lua require('custom.utils.neorg_setup_check').check() + ``` + +2. **Open your notes index**: + + ```vim + :Neorg workspace notes + ``` + +3. **Create a journal entry**: + Press `nj` or use command `:Neorg journal today` + +4. **Navigate workspaces**: + Press `nw` to open the workspace selector + +5. **Export to Markdown**: + Press `nem` within a Neorg file + +## What's Changed from Previous Configuration + +- Improved visual appearance with diamond icons +- Added more workspace options +- Expanded keybinding set with better documentation +- Added support for advanced list manipulation +- Enhanced journal capabilities +- Added calendar support for date navigation +- Improved organization with an index file + +Refer to the full documentation in: + +- `/home/kali/.config/nvim/lua/custom/plugins/neorg_guide.md` +- `/home/kali/.config/nvim/lua/custom/plugins/neorg_keymaps_reference.md` diff --git a/lua/custom/plugins/telescope_fix.lua.back b/lua/custom/plugins/telescope_fix.lua.back deleted file mode 100644 index 418650f9..00000000 --- a/lua/custom/plugins/telescope_fix.lua.back +++ /dev/null @@ -1,34 +0,0 @@ --- Fix for Telescope error with nil paths --- return { --- "nvim-telescope/telescope.nvim", --- -- This will only modify the existing telescope configuration --- config = function() --- local telescope = require('telescope') - --- -- Only apply our patch if telescope is loaded --- local utils = require('telescope.utils') --- local original_path_expand = utils.path_expand - --- -- Override path_expand with a safer version that handles nil paths --- utils.path_expand = function(path) --- if path == nil then --- -- Return the current working directory if path is nil --- return vim.fn.getcwd() or vim.fn.expand('%:p:h') or '.' --- end --- return original_path_expand(path) --- end - --- -- Any additional telescope settings can be set here --- telescope.setup({ --- defaults = { --- path_display = { "truncate" }, --- mappings = { --- i = { --- [""] = false, --- [""] = false, --- }, --- }, --- }, --- }) --- end, --- } diff --git a/lua/custom/plugins/trouble.lua b/lua/custom/plugins/trouble.lua index ab1c6d89..39806230 100644 --- a/lua/custom/plugins/trouble.lua +++ b/lua/custom/plugins/trouble.lua @@ -77,17 +77,14 @@ return { }, config = function(_, opts) require('trouble').setup(opts) - -- Add which-key group + + -- Add which-key group using the new v3 spec API local ok, which_key = pcall(require, 'which-key') - -- if ok then - -- -- Use standard which-key format that's known to work - -- which_key.register({ - -- ["x"] = { name = "Trouble/Diagnostics" }, - -- }) - - -- which_key.register({ - -- ["g"] = { name = "Goto" }, - -- }) - -- end + if ok then + which_key.add({ + { "x", group = "Trouble/Diagnostics" }, + { "g", group = "Goto" }, + }) + end end, } diff --git a/lua/custom/plugins/which_key_integration.lua b/lua/custom/plugins/which_key_integration.lua new file mode 100644 index 00000000..f2e42107 --- /dev/null +++ b/lua/custom/plugins/which_key_integration.lua @@ -0,0 +1,275 @@ +-- --[[ +-- Which-Key Integration Plugin - Latest v3 Configuration + +-- This file sets up which-key with the latest v3 API and configuration. +-- which-key v3 uses a new spec-based system for defining keymaps. +-- ]] + +-- return { +-- { +-- 'folke/which-key.nvim', +-- event = "VeryLazy", +-- opts = { +-- preset = "modern", -- "classic", "modern", or "helix" +-- delay = function(ctx) +-- return ctx.plugin and 0 or 200 +-- end, +-- plugins = { +-- marks = true, -- shows a list of your marks on ' and ` +-- registers = true, -- shows your registers on " in NORMAL or in INSERT mode +-- spelling = { +-- enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions +-- suggestions = 20, -- how many suggestions should be shown in the list? +-- }, +-- presets = { +-- operators = true, -- adds help for operators like d, y, ... +-- motions = true, -- adds help for motions +-- text_objects = true, -- help for text objects triggered after entering an operator +-- windows = true, -- default bindings on +-- nav = true, -- misc bindings to work with windows +-- z = true, -- bindings for folds, spelling and others prefixed with z +-- g = true, -- bindings for prefixed with g +-- }, +-- }, +-- spec = { +-- { "g", group = "goto" }, +-- { "gz", group = "surround" }, +-- { "]", group = "next" }, +-- { "[", group = "prev" }, +-- { "", group = "tabs" }, +-- { "b", group = "buffer" }, +-- { "c", group = "code" }, +-- { "f", group = "file/find" }, +-- { "g", group = "git" }, +-- { "h", group = "harpoon" }, +-- { "l", group = "leetcode" }, +-- { "n", group = "neorg" }, +-- { "q", group = "quit/session" }, +-- { "s", group = "search" }, +-- { "t", group = "toggle/tab" }, +-- { "w", group = "windows" }, +-- { "x", group = "diagnostics/quickfix" }, +-- }, +-- icons = { +-- breadcrumb = "»", -- symbol used in the command line area that shows your active key combo +-- separator = "→", -- symbol used between a key and it's label +-- group = "+", -- symbol prepended to a group +-- mappings = vim.g.have_nerd_font, +-- }, +-- win = { +-- border = "rounded", -- none, single, double, shadow, rounded +-- position = "bottom", -- bottom, top +-- margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] +-- padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] +-- winblend = 0, -- value between 0-100 0 for fully opaque and 100 for fully transparent +-- }, +-- layout = { +-- height = { min = 4, max = 25 }, -- min and max height of the columns +-- width = { min = 20, max = 50 }, -- min and max width of the columns +-- spacing = 3, -- spacing between columns +-- align = "center", -- align columns left, center or right +-- }, +-- show_help = true, -- show help message on the command line when the popup is visible +-- show_keys = true, -- show the currently pressed key and its label as a message in the command line +-- }, +-- config = function(_, opts) +-- local wk = require("which-key") +-- wk.setup(opts) + +-- -- Use vim.schedule to ensure modules are loaded after Vim is ready +-- vim.schedule(function() +-- -- Load which-key setup with customized configuration +-- require('custom.which_key_setup').setup() + +-- -- Load core keymaps +-- pcall(function() require('custom.keymaps').setup() end) + +-- -- Load plugin-specific keymaps +-- pcall(function() require('custom.plugin_keymaps').setup() end) +-- end) +-- end, +-- -- Load on specific events with higher priority +-- event = "VeryLazy", +-- priority = 1000, -- High priority to ensure it loads first +-- } +-- } +--[[ + Which-Key Integration Plugin - Latest v3 Configuration + + This file sets up which-key with the latest v3 API and configuration. + Official documentation: https://github.com/folke/which-key.nvim +]] + +return { + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + preset = "modern", -- "classic", "modern", or "helix" + -- Delay before showing the popup. Can be a number or a function that returns a number. + -- 0 to disable, or a function that returns the delay based on the current context + delay = function(ctx) + return ctx.plugin and 0 or 200 + end, + + -- Filter to exclude mappings without descriptions or that match certain patterns + filter = function(mapping) + -- Exclude mappings without descriptions + return mapping.desc and mapping.desc ~= "" + end, + + -- You can add any mappings here, or use `require("which-key").add()` later + spec = { + { + mode = { "n", "v" }, + { "", group = "tabs" }, + { "b", group = "buffer" }, + { "c", group = "code/copilot" }, + { "f", group = "file/find" }, + { "g", group = "git" }, + { "gh", group = "hunks" }, + { "h", group = "harpoon" }, + { "l", group = "leetcode" }, + { "n", group = "neorg" }, + { "q", group = "quit/session" }, + { "s", group = "search" }, + { "t", group = "toggle/tab" }, + { "u", group = "ui" }, + { "w", group = "windows" }, + { "x", group = "diagnostics/quickfix" }, + { "[", group = "prev" }, + { "]", group = "next" }, + { "g", group = "goto" }, + { "gs", group = "surround" }, + { "z", group = "fold" }, + }, + }, + + -- Window configuration + win = { + border = "rounded", + no_overlap = true, + padding = { 1, 2 }, -- extra window padding [top/bottom, right/left] + title = true, + title_pos = "center", + zindex = 1000, + }, + + -- Layout configuration + layout = { + width = { min = 20 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + }, + + -- Key bindings for the which-key buffer + keys = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + + -- Sort mappings + sort = { "local", "order", "group", "alphanum", "mod" }, + + -- Expand groups when <= n mappings + expand = 0, + + -- Replacements for how keys and descriptions are displayed + replace = { + key = { + function(key) + return require("which-key.view").format(key) + end, + -- { "", "SPC" }, + }, + desc = { + { "%(?(.*)%)?", "%1" }, + { "^%+", "" }, + { "<[cC]md>", "" }, + { "<[cC][rR]>", "" }, + { "<[sS]ilent>", "" }, + { "^lua%s+", "" }, + { "^call%s+", "" }, + { "^:%s*", "" }, + }, + }, + + -- Icons configuration + icons = { + breadcrumb = "»", -- symbol used in the command line area that shows your active key combo + separator = "➜", -- symbol used between a key and it's label + group = "+", -- symbol prepended to a group + ellipsis = "…", + mappings = vim.g.have_nerd_font, -- set to false to disable all mapping icons + rules = {}, + colors = true, + -- Icon keys for different key types + keys = vim.g.have_nerd_font and {} or { + Up = " ", + Down = " ", + Left = " ", + Right = " ", + C = "󰘴 ", + M = "󰘵 ", + D = "󰘳 ", + S = "󰘶 ", + CR = "󰌑 ", + Esc = "󱊷 ", + ScrollWheelDown = "󱕐 ", + ScrollWheelUp = "󱕑 ", + NL = "󰌑 ", + BS = "󰁮", + Space = "󱁐 ", + Tab = "󰌒 ", + F1 = "󱊫", + F2 = "󱊬", + F3 = "󱊭", + F4 = "󱊮", + F5 = "󱊯", + F6 = "󱊰", + F7 = "󱊱", + F8 = "󱊲", + F9 = "󱊳", + F10 = "󱊴", + F11 = "󱊵", + F12 = "󱊶", + }, + }, + + -- Show help and keys + show_help = true, + show_keys = true, + + -- Disable which-key for certain file types or buffer types + disable = { + buftypes = {}, + filetypes = {}, + }, + }, + + config = function(_, opts) + local wk = require("which-key") + wk.setup(opts) + + -- Load keymap modules after which-key is ready + vim.schedule(function() + -- Load core keymaps if they exist + local core_keymaps_ok, _ = pcall(require, 'custom.keymaps') + if core_keymaps_ok then + pcall(function() require('custom.keymaps').setup() end) + end + + -- Load which-key specific setup + local wk_setup_ok, _ = pcall(require, 'custom.which_key_setup') + if wk_setup_ok then + pcall(function() require('custom.which_key_setup').setup() end) + end + + -- Load plugin-specific keymaps + local plugin_keymaps_ok, _ = pcall(require, 'custom.plugin_keymaps') + if plugin_keymaps_ok then + pcall(function() require('custom.plugin_keymaps').setup() end) + end + end) + end, + } +} diff --git a/lua/custom/utils/neorg_setup_check.lua b/lua/custom/utils/neorg_setup_check.lua new file mode 100644 index 00000000..e69de29b diff --git a/lua/custom/which_key_setup.lua b/lua/custom/which_key_setup.lua new file mode 100644 index 00000000..80483d02 --- /dev/null +++ b/lua/custom/which_key_setup.lua @@ -0,0 +1,152 @@ +--[[ + Which-key configuration + + This file contains the configuration for which-key, + organizing keybindings into logical groups with descriptions. +]] + +---@diagnostic disable-next-line: undefined-global +local vim = vim +local M = {} + +function M.setup() + -- Check if which-key is available + local status_ok, wk = pcall(require, 'which-key') + if not status_ok then + return + end + + -- Use the modern which-key v3 API with add() + -- Define common keybindings and groups + wk.add { + -- Most frequent operations + { 'w', 'w', desc = 'Save file' }, + { 'q', 'q', desc = 'Quit' }, + { 'Q', 'qa!', desc = 'Force quit all' }, + { '/', 'nohlsearch', desc = 'Clear highlights' }, + { 'e', 'Explore', desc = 'Open file explorer' }, + + -- File operations (f) + { 'f', group = 'Find/Files' }, + { 'ff', 'Telescope find_files', desc = 'Find files' }, + { 'fg', 'Telescope live_grep', desc = 'Live grep' }, + { 'fb', 'Telescope buffers', desc = 'Find buffers' }, + { 'fr', 'Telescope oldfiles', desc = 'Recent files' }, + + -- Buffer operations (b) + { 'b', group = 'Buffers' }, + { 'bb', 'Telescope buffers', desc = 'Browse buffers' }, + { 'bd', 'bd', desc = 'Delete buffer' }, + { 'bn', 'bn', desc = 'Next buffer' }, + { 'bp', 'bp', desc = 'Previous buffer' }, + + -- Git operations (g) + { 'g', group = 'Git' }, + { 'gs', 'Telescope git_status', desc = 'Git status' }, + { 'gc', 'Telescope git_commits', desc = 'Git commits' }, + { 'gb', 'Telescope git_branches', desc = 'Git branches' }, + + -- Code operations (c) + { 'c', group = 'Code/Copilot' }, + { 'ca', 'lua vim.lsp.buf.code_action()', desc = 'Code actions' }, + { 'cf', 'lua vim.lsp.buf.format()', desc = 'Format code' }, + + -- Harpoon (h) + { 'h', group = 'Harpoon' }, + { 'ha', "lua require('harpoon.mark').add_file()", desc = 'Add file' }, + { 'hh', "lua require('harpoon.ui').toggle_quick_menu()", desc = 'Toggle menu' }, + { 'h1', "lua require('harpoon.ui').nav_file(1)", desc = 'File 1' }, + { 'h2', "lua require('harpoon.ui').nav_file(2)", desc = 'File 2' }, + { 'h3', "lua require('harpoon.ui').nav_file(3)", desc = 'File 3' }, + { 'h4', "lua require('harpoon.ui').nav_file(4)", desc = 'File 4' }, + + -- LeetCode (l) + { 'l', group = 'LeetCode' }, + { 'll', 'Leet', desc = 'Open LeetCode' }, + { 'ld', 'Leet daily', desc = 'Daily challenge' }, + { 'lr', 'Leet random', desc = 'Random problem' }, + { 'ls', 'Leet submit', desc = 'Submit solution' }, + { 'lt', 'Leet test', desc = 'Test solution' }, + + -- Tab operations (t) + { 't', group = 'Tabs' }, + { 'tn', 'tabnew', desc = 'New tab' }, + { 'tc', 'tabclose', desc = 'Close tab' }, + { 'to', 'tabnewTelescope find_files', desc = 'New tab with file' }, + { 't1', '1gt', desc = 'Tab 1' }, + { 't2', '2gt', desc = 'Tab 2' }, + { 't3', '3gt', desc = 'Tab 3' }, + { 't4', '4gt', desc = 'Tab 4' }, + + -- Window operations (w) + { 'w', group = 'Windows' }, + { 'wv', 'vsplit', desc = 'Split vertically' }, + { 'ws', 'split', desc = 'Split horizontally' }, + { 'wq', 'q', desc = 'Close window' }, + { 'wo', 'o', desc = 'Close other windows' }, + { 'wh', 'h', desc = 'Go to left window' }, + { 'wj', 'j', desc = 'Go to lower window' }, + { 'wk', 'k', desc = 'Go to upper window' }, + { 'wl', 'l', desc = 'Go to right window' }, + + -- Terminal operations (tt) + { 'tt', group = 'Terminal' }, + { 'ttt', 'ToggleTerm', desc = 'Toggle terminal' }, + { 'ttf', 'ToggleTerm direction=float', desc = 'Floating terminal' }, + { 'tth', 'ToggleTerm size=10 direction=horizontal', desc = 'Horizontal terminal' }, + { 'ttv', 'ToggleTerm size=80 direction=vertical', desc = 'Vertical terminal' }, + + -- Trouble/Diagnostics (x) + { 'x', group = 'Diagnostics/Trouble' }, + { 'xx', 'TroubleToggle', desc = 'Toggle Trouble' }, + { 'xw', 'TroubleToggle workspace_diagnostics', desc = 'Workspace diagnostics' }, + { 'xd', 'TroubleToggle document_diagnostics', desc = 'Document diagnostics' }, + { 'xq', 'TroubleToggle quickfix', desc = 'Quickfix list' }, + { 'xl', 'TroubleToggle loclist', desc = 'Location list' }, + + -- Neorg (n) + { 'n', group = 'Neorg' }, + { 'ni', 'Neorg index', desc = 'Index' }, + { 'nr', 'Neorg return', desc = 'Return' }, + { 'nt', 'Neorg toggle-concealer', desc = 'Toggle concealer' }, + { 'nm', 'Neorg inject-metadata', desc = 'Inject metadata' }, + + -- Neorg Journal (nj) + { 'nj', group = 'Journal' }, + { 'njj', 'Neorg journal today', desc = 'Today' }, + { 'njt', 'Neorg journal tomorrow', desc = 'Tomorrow' }, + { 'njy', 'Neorg journal yesterday', desc = 'Yesterday' }, + + -- Neorg Workspace (nw) + { 'nw', group = 'Workspace' }, + { 'nwn', 'Neorg workspace notes', desc = 'Notes' }, + { 'nww', 'Neorg workspace work', desc = 'Work' }, + { 'nwp', 'Neorg workspace personal', desc = 'Personal' }, + + -- Neorg Export (ne) + { 'ne', group = 'Export' }, + { 'neh', 'Neorg export to-html', desc = 'To HTML' }, + { 'nem', 'Neorg export to-markdown', desc = 'To Markdown' }, + { 'nep', 'Neorg export to-pdf', desc = 'To PDF' }, + + -- Diagnostics navigation + { '[d', 'lua vim.diagnostic.goto_prev()', desc = 'Previous diagnostic' }, + { ']d', 'lua vim.diagnostic.goto_next()', desc = 'Next diagnostic' }, + } + + -- Visual mode mappings + wk.add { + { 'c', group = 'Code', mode = 'v' }, + { 'cc', "'<,'>CommentToggle", desc = 'Comment selection', mode = 'v' }, + { 'y', '"+y', desc = 'Yank to system clipboard', mode = 'v' }, + { 'p', '"+p', desc = 'Paste from system clipboard', mode = 'v' }, + } + + -- Buffer navigation shortcuts + wk.add { + { '', 'bnext', desc = 'Next buffer' }, + { '', 'bprevious', desc = 'Previous buffer' }, + } +end + +return M