diff --git a/.gitignore b/.gitignore index 005b535b606..29d9a23fe4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,39 @@ +# Generated files tags -test.sh .luarc.json -nvim +lazy-lock.json + +# Session files +sessions/ + +# Compiled Lua sources +luac.out + +# Logs and databases +*.log +*.sqlite + +# Temporary files +*.swp +*.swo +*~ +.DS_Store +# Plugin directories that should be ignored spell/ -lazy-lock.json +.backup/ +.undo/ +.swap/ + +# Local development files +.env +.envrc +.direnv/ +test.sh +test.py + +# Compiled plugins +plugin/packer_compiled.lua + +# LSP data +.lsp/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000000..134c17cb445 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "stylua.targetReleaseVersion": "latest" +} \ No newline at end of file diff --git a/README.md b/README.md index aa5f4fc8f1e..a2638080b21 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,267 @@ -# kickstart.nvim +# Customized Neovim Configuration + +This Neovim configuration is based on kickstart.nvim and has been customized with additional features and language support. + +## Features + +### Language Support + +#### Go Development +- Full LSP support via `gopls` +- Advanced formatting with `gofumpt` +- Import management with `goimports` +- Linting with `golangci-lint` +- Debugging support with Delve + +#### Zig Development +- LSP support via `zls` +- Auto-formatting on save +- Syntax highlighting + +#### C Development +- LSP support via `clangd` +- Code formatting with `clang-format` +- Debugging with `codelldb` +- Enhanced features through `clangd_extensions.nvim`: + - Inlay hints + - AST viewer + - Header/source switching + - Symbol info + +#### Python Development +- LSP support via `pyright` +- Code formatting with `black` +- Linting with `ruff` +- Debugging with `debugpy` +- Virtual environment support +- Auto-detection of Python path + +### Debug Adapter Protocol (DAP) +Integrated debugging support with a consistent interface across languages: + +#### Keybindings +- `pb` - Toggle breakpoint +- `pc` - Continue debugging +- `pn` - Step over (Next) +- `pi` - Step into +- `po` - Step out +- `pr` - Debug REPL +- `pl` - Run last debug session +- `px` - Toggle debug UI + +#### Debug UI Features +- Left sidebar: + - Scopes + - Breakpoints + - Call stack + - Watches +- Bottom panel: + - REPL + - Console output + +### Additional Plugins and Features + +#### Snacks.nvim Integration +- Smooth scrolling +- Enhanced terminal support +- Custom dashboard +- Git integration +- Improved display features + +#### Profiling Support +Integrated profiling for multiple languages using `mp`: + +##### Go Profiling +- Uses `pprof` for CPU and memory profiling +- Runs benchmarks and generates profile data +- Opens interactive web UI for visualization +- Shows both CPU and memory profiles +- Supports flame graphs and call graphs + +##### Python Profiling +- Uses `py-spy` for sampling profiler +- Non-intrusive profiling (doesn't modify code) +- Generates SVG flame graphs +- Shows CPU usage and call stacks +- Works with running processes + +##### C/C++ Profiling +- Uses `perf` for system-wide profiling +- Shows CPU usage and call graphs +- Supports hardware performance counters +- Low-overhead profiling +- Kernel and userspace profiling + +For Zig, profiling is still in development in the language tooling. Once stable profiling tools are available, they will be integrated. + +## Installation Guide + +### Core Dependencies + +```bash +# Ubuntu/Debian +sudo apt update +sudo apt install -y git curl unzip ripgrep fd-find make gcc g++ xclip + +# Arch Linux +sudo pacman -S git curl unzip ripgrep fd make gcc xclip +``` + +### Language-Specific Installation + +#### Go Development Tools +```bash +# Install Go +wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz +sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz +echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.bashrc +source ~/.bashrc + +# Install Go tools (will be handled by Mason, but can be installed manually) +go install golang.org/x/tools/gopls@latest +go install mvdan.cc/gofumpt@latest +go install golang.org/x/tools/cmd/goimports@latest +go install github.com/go-delve/delve/cmd/dlv@latest +go install github.com/google/pprof@latest +``` + +#### Zig Development Tools +```bash +# Install Zig (latest version) +wget https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz +sudo tar -C /usr/local -xf zig-linux-x86_64-0.11.0.tar.xz +echo 'export PATH=$PATH:/usr/local/zig-linux-x86_64-0.11.0' >> ~/.bashrc +source ~/.bashrc + +# ZLS will be installed by Mason +``` + +#### C/C++ Development Tools +```bash +# Ubuntu/Debian +sudo apt install -y clang clangd clang-format lldb linux-perf + +# Arch Linux +sudo pacman -S clang lldb perf +``` + +#### Python Development Tools +```bash +# Install Python and pip +sudo apt install -y python3 python3-pip python3-venv + +# Install global tools (will be handled by Mason, but can be installed manually) +pip3 install --user black ruff debugpy py-spy + +# For each project, it's recommended to use a virtual environment: +python3 -m venv .venv +source .venv/bin/activate +pip install black ruff debugpy py-spy +``` + +### Neovim Installation + +#### Install Latest Neovim +```bash +# Ubuntu/Debian +sudo add-apt-repository ppa:neovim-ppa/unstable +sudo apt update +sudo apt install -y neovim + +# Arch Linux +sudo pacman -S neovim +``` + +#### Install Configuration +```bash +# Backup existing config if needed +mv ~/.config/nvim ~/.config/nvim.bak +mv ~/.local/share/nvim ~/.local/share/nvim.bak +mv ~/.local/state/nvim ~/.local/state/nvim.bak +mv ~/.cache/nvim ~/.cache/nvim.bak + +# Clone this configuration +git clone https://github.com/yourusername/nvim-config.git ~/.config/nvim +``` + +### Post-Installation + +1. Start Neovim: + ```bash + nvim + ``` + This will automatically: + - Install the plugin manager (Lazy) + - Install all plugins + - Install LSP servers and tools via Mason + +2. Verify installation: + ``` + :checkhealth + ``` + +3. Install language servers and tools: + ``` + :Mason + ``` + Use `i` to install any missing tools. + +### Troubleshooting + +#### Common Issues + +1. **LSP not working** + - Check if the language server is installed: `:Mason` + - Verify server status: `:LspInfo` + - Install language server manually if needed + +2. **Debugger not working** + - Ensure debugger is installed: `:Mason` + - Check if language tools are in PATH + - For Python, make sure you're in the correct virtual environment + +3. **Profiler issues** + - For Go: Ensure `pprof` is installed and `go` is in PATH + - For Python: Check `py-spy` installation and permissions + - For C/C++: `perf` might need root permissions: `sudo sysctl -w kernel.perf_event_paranoid=1` + +## Usage + +### Go Development +1. Open a Go file +2. LSP features will work automatically +3. Use `gofumpt` for enhanced formatting +4. Debug your Go programs with Delve + +### Zig Development +1. Open a Zig file +2. LSP features and formatting will work automatically + +### C Development +1. Open a C file +2. LSP features will work automatically +3. For debugging: + - Build your program with debug symbols (`gcc -g`) + - Set breakpoints and start debugging + - Use the debug UI to inspect variables and control execution + +### Python Development +1. Open a Python file +2. LSP features will work automatically +3. Use `black` for code formatting +4. For debugging: + - Set breakpoints with `pb` + - Start debugging with `pc` + - Python path will be auto-detected from virtual environments + - Use the debug UI to inspect variables and control execution + +## Customization +- LSP settings can be modified in `lua/plugins/nvim-lspconfig.lua` +- Debug configurations are in `lua/plugins/coding.lua` +- Additional language support can be added through Mason and appropriate LSP configurations + +## Contributing +Feel free to submit issues and enhancement requests! ## Introduction @@ -61,7 +324,7 @@ fork to your machine using one of the commands below, depending on your OS. You likely want to remove `lazy-lock.json` from your fork's `.gitignore` file too - it's ignored in the kickstart repo to make maintenance easier, but it's -[recommended to track it in version control](https://lazy.folke.io/usage/lockfile). +[recommended to track it in version control](https://lazy.folke.io/usage#lockfile). #### Clone kickstart.nvim > **NOTE** @@ -235,4 +498,3 @@ 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/init.lua b/init.lua index 7758df93a2e..8395961dc41 100644 --- a/init.lua +++ b/init.lua @@ -1,211 +1,16 @@ ---[[ +---@diagnostic disable: undefined-global +local config_path = vim.fn.stdpath 'config' +local lua_path = config_path .. '/lua' +package.path = lua_path .. '/?.lua;' .. lua_path .. '/?/init.lua;' .. config_path .. '/?.lua;' .. config_path .. '/?/init.lua;' .. package.path -===================================================================== -==================== READ THIS BEFORE CONTINUING ==================== -===================================================================== -======== .-----. ======== -======== .----------------------. | === | ======== -======== |.-""""""""""""""""""-.| |-----| ======== -======== || || | === | ======== -======== || KICKSTART.NVIM || |-----| ======== -======== || || | === | ======== -======== || || |-----| ======== -======== ||:Tutor || |:::::| ======== -======== |'-..................-'| |____o| ======== -======== `"")----------------(""` ___________ ======== -======== /::::::::::| |::::::::::\ \ no mouse \ ======== -======== /:::========| |==hjkl==:::\ \ required \ ======== -======== '""""""""""""' '""""""""""""' '""""""""""' ======== -======== ======== -===================================================================== -===================================================================== +require('core.keymaps').setup() +require('options.autocmds').setup() +require('options.settings').setup() -What is Kickstart? +local plugins = require 'plugins' - Kickstart.nvim is *not* a distribution. - - Kickstart.nvim is a starting point for your own configuration. - The goal is that you can read every line of code, top-to-bottom, understand - what your configuration is doing, and modify it to suit your needs. - - Once you've done that, you can start exploring, configuring and tinkering to - make Neovim your own! That might mean leaving Kickstart just the way it is for a while - or immediately breaking it into modular pieces. It's up to you! - - If you don't know anything about Lua, I recommend taking some time to read through - a guide. One possible example which will only take 10-15 minutes: - - https://learnxinyminutes.com/docs/lua/ - - After understanding a bit more about Lua, you can use `:help lua-guide` as a - reference for how Neovim integrates Lua. - - :help lua-guide - - (or HTML version): https://neovim.io/doc/user/lua-guide.html - -Kickstart Guide: - - TODO: The very first thing you should do is to run the command `:Tutor` in Neovim. - - If you don't know what this means, type the following: - - - - : - - Tutor - - - - (If you already know the Neovim basics, you can skip this step.) - - Once you've completed that, you can continue working through **AND READING** the rest - of the kickstart init.lua. - - Next, run AND READ `:help`. - This will open up a help window with some basic information - about reading, navigating and searching the builtin help documentation. - - This should be the first place you go to look when you're stuck or confused - with something. It's one of my favorite Neovim features. - - MOST IMPORTANTLY, we provide a keymap "sh" to [s]earch the [h]elp documentation, - which is very useful when you're not exactly sure of what you're looking for. - - I have left several `:help X` comments throughout the init.lua - These are hints about where to find more information about the relevant settings, - plugins or Neovim features used in Kickstart. - - NOTE: Look for lines like this - - Throughout the file. These are for you, the reader, to help you understand what is happening. - Feel free to delete them once you know what you're doing, but they should serve as a guide - for when you are first encountering a few different constructs in your Neovim config. - -If you experience any errors while trying to install kickstart, run `:checkhealth` for more info. - -I hope you enjoy your Neovim journey, -- TJ - -P.S. You can delete this when you're done too. It's your config now! :) ---]] - --- Set as the leader key --- See `:help mapleader` --- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - --- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false - --- [[ Setting options ]] --- See `:help vim.opt` --- NOTE: You can change these options as you wish! --- For more options, you can see `:help option-list` - --- Make line numbers default -vim.opt.number = true --- You can also add relative line numbers, to help with jumping. --- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true - --- Enable mouse mode, can be useful for resizing splits for example! -vim.opt.mouse = 'a' - --- Don't show the mode, since it's already in the status line -vim.opt.showmode = false - --- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.schedule(function() - vim.opt.clipboard = 'unnamedplus' -end) - --- Enable break indent -vim.opt.breakindent = true - --- Save undo history -vim.opt.undofile = true - --- Case-insensitive searching UNLESS \C or one or more capital letters in the search term -vim.opt.ignorecase = true -vim.opt.smartcase = true - --- Keep signcolumn on by default -vim.opt.signcolumn = 'yes' - --- Decrease update time -vim.opt.updatetime = 250 - --- Decrease mapped sequence wait time -vim.opt.timeoutlen = 300 - --- Configure how new splits should be opened -vim.opt.splitright = true -vim.opt.splitbelow = true - --- Sets how neovim will display certain whitespace characters in the editor. --- See `:help 'list'` --- and `:help 'listchars'` -vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } - --- Preview substitutions live, as you type! -vim.opt.inccommand = 'split' - --- Show which line your cursor is on -vim.opt.cursorline = true - --- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 10 - --- [[ Basic Keymaps ]] --- See `:help vim.keymap.set()` - --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` -vim.keymap.set('n', '', 'nohlsearch') - --- Diagnostic keymaps -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) - --- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier --- for people to discover. Otherwise, you normally need to press , which --- is not what someone will guess without a bit more experience. --- --- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping --- or just use to exit terminal mode -vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) - --- TIP: Disable arrow keys in normal mode --- vim.keymap.set('n', '', 'echo "Use h to move!!"') --- vim.keymap.set('n', '', 'echo "Use l to move!!"') --- vim.keymap.set('n', '', 'echo "Use k to move!!"') --- vim.keymap.set('n', '', 'echo "Use j to move!!"') - --- Keybinds to make split navigation easier. --- Use CTRL+ to switch between windows --- --- See `:help wincmd` for a list of all window commands -vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - --- [[ Basic Autocommands ]] --- See `:help lua-guide-autocommands` - --- Highlight when yanking (copying) text --- Try it with `yap` in normal mode --- See `:help vim.highlight.on_yank()` -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) - --- [[ Install `lazy.nvim` plugin manager ]] --- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info -local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } @@ -215,737 +20,7 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) --- [[ Configure and install plugins ]] --- --- To check the current status of your plugins, run --- :Lazy --- --- You can press `?` in this menu for help. Use `:q` to close the window --- --- To update plugins you can run --- :Lazy update --- --- NOTE: Here is where you install your plugins. -require('lazy').setup({ - -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). - 'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically - - -- NOTE: Plugins can also be added by using a table, - -- with the first argument being the link and the following - -- keys can be used to configure plugin behavior/loading/etc. - -- - -- Use `opts = {}` to force a plugin to be loaded. - -- - - -- Here is a more advanced example where we pass configuration - -- options to `gitsigns.nvim`. This is equivalent to the following Lua: - -- require('gitsigns').setup({ ... }) - -- - -- See `:help gitsigns` to understand what the configuration keys do - { -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, - - -- NOTE: Plugins can also be configured to run Lua code when they are loaded. - -- - -- This is often very useful to both group configuration, as well as handle - -- lazy loading plugins that don't need to be loaded immediately at startup. - -- - -- For example, in the following configuration, we use: - -- event = 'VimEnter' - -- - -- which loads which-key before all the UI elements are loaded. Events can be - -- normal autocommands events (`:help autocmd-events`). - -- - -- 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.opt.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 = { - { 'c', group = '[C]ode', mode = { 'n', 'x' } }, - { 'd', group = '[D]ocument' }, - { 'r', group = '[R]ename' }, - { 's', group = '[S]earch' }, - { 'w', group = '[W]orkspace' }, - { 't', group = '[T]oggle' }, - { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, - }, - }, - }, - - -- NOTE: Plugins can specify dependencies. - -- - -- The dependencies are proper plugin specifications as well - anything - -- you do for a plugin at the top level, you can do for a dependency. - -- - -- Use the `dependencies` key to specify the dependencies of a particular plugin - - { -- Fuzzy Finder (files, lsp, etc) - 'nvim-telescope/telescope.nvim', - event = 'VimEnter', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.nvim', - { -- If encountering errors, see telescope-fzf-native README for installation instructions - 'nvim-telescope/telescope-fzf-native.nvim', - - -- `build` is used to run some command when the plugin is installed/updated. - -- This is only run then, not every time Neovim starts up. - build = 'make', - - -- `cond` is a condition used to determine whether this plugin should be - -- installed and loaded. - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, - { 'nvim-telescope/telescope-ui-select.nvim' }, - - -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, - }, - config = function() - -- Telescope is a fuzzy finder that comes with a lot of different things that - -- it can fuzzy find! It's more than just a "file finder", it can search - -- many different aspects of Neovim, your workspace, LSP, and more! - -- - -- The easiest way to use Telescope, is to start by doing something like: - -- :Telescope help_tags - -- - -- After running this command, a window will open up and you're able to - -- type in the prompt window. You'll see a list of `help_tags` options and - -- a corresponding preview of the help. - -- - -- Two important keymaps to use while in Telescope are: - -- - Insert mode: - -- - Normal mode: ? - -- - -- This opens a window that shows you all of the keymaps for the current - -- Telescope picker. This is really useful to discover what Telescope can - -- do as well as how to actually do it! - - -- [[ Configure Telescope ]] - -- See `:help telescope` and `:help telescope.setup()` - require('telescope').setup { - -- You can put your default mappings / updates / etc. in here - -- All the info you're looking for is in `:help telescope.setup()` - -- - -- defaults = { - -- mappings = { - -- i = { [''] = 'to_fuzzy_refine' }, - -- }, - -- }, - -- pickers = {} - extensions = { - ['ui-select'] = { - require('telescope.themes').get_dropdown(), - }, - }, - } - - -- Enable Telescope extensions if they are installed - pcall(require('telescope').load_extension, 'fzf') - pcall(require('telescope').load_extension, 'ui-select') - - -- See `:help telescope.builtin` - local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - 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', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - - -- Slightly advanced example of overriding default behavior and theme - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to Telescope to change the theme, layout, etc. - builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) - - -- It's also possible to pass additional configuration options. - -- See `:help telescope.builtin.live_grep()` for information about particular keys - vim.keymap.set('n', 's/', function() - builtin.live_grep { - grep_open_files = true, - prompt_title = 'Live Grep in Open Files', - } - end, { desc = '[S]earch [/] in Open Files' }) - - -- Shortcut for searching your Neovim configuration files - vim.keymap.set('n', 'sn', function() - builtin.find_files { cwd = vim.fn.stdpath 'config' } - end, { desc = '[S]earch [N]eovim files' }) - end, - }, - - -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, - }, - }, - }, - { 'Bilal2453/luvit-meta', lazy = true }, - { - -- Main LSP Configuration - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants - 'williamboman/mason-lspconfig.nvim', - 'WhoIsSethDaniel/mason-tool-installer.nvim', - - -- Useful status updates for LSP. - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, - - -- Allows extra capabilities provided by nvim-cmp - 'hrsh7th/cmp-nvim-lsp', - }, - config = function() - -- Brief aside: **What is LSP?** - -- - -- LSP is an initialism you've probably heard, but might not understand what it is. - -- - -- LSP stands for Language Server Protocol. It's a protocol that helps editors - -- and language tooling communicate in a standardized fashion. - -- - -- In general, you have a "server" which is some tool built to understand a particular - -- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers - -- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone - -- processes that communicate with some "client" - in this case, Neovim! - -- - -- LSP provides Neovim with features like: - -- - Go to definition - -- - Find references - -- - Autocompletion - -- - Symbol Search - -- - and more! - -- - -- Thus, Language Servers are external tools that must be installed separately from - -- Neovim. This is where `mason` and related plugins come into play. - -- - -- If you're wondering about lsp vs treesitter, you can check out the wonderfully - -- and elegantly composed help section, `:help lsp-vs-treesitter` - - -- This function gets run when an LSP attaches to a particular buffer. - -- That is to say, every time a new file is opened that is associated with - -- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this - -- function will be executed to configure the current buffer - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }), - callback = function(event) - -- NOTE: Remember that Lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local map = function(keys, func, desc, mode) - mode = mode or 'n' - vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) - end - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . - map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - - -- Find references for the word under your cursor. - map('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. - map('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. - map('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. - map('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. - map('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - -- Rename the variable under your cursor. - -- Most Language Servers support renaming across files, etc. - map('rn', vim.lsp.buf.rename, '[R]e[n]ame') - - -- Execute a code action, usually your cursor needs to be on top of an error - -- or a suggestion from your LSP for this to activate. - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) - - -- WARN: This is not Goto Definition, this is Goto Declaration. - -- For example, in C this would take you to the header. - map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - - -- The following two autocommands are used to highlight references of the - -- word under your cursor when your cursor rests there for a little while. - -- See `:help CursorHold` for information about when this is executed - -- - -- When you move your cursor, the highlights will be cleared (the second autocommand). - local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) - vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.document_highlight, - }) - - vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { - buffer = event.buf, - group = highlight_augroup, - callback = vim.lsp.buf.clear_references, - }) - - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } - end, - }) - end - - -- The following code creates a keymap to toggle inlay hints in your - -- code, if the language server you are using supports them - -- - -- This may be unwanted, since they displace some of your code - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') - end - end, - }) - - -- Change diagnostic symbols in the sign column (gutter) - -- if vim.g.have_nerd_font then - -- local signs = { ERROR = '', WARN = '', INFO = '', HINT = '' } - -- local diagnostic_signs = {} - -- for type, icon in pairs(signs) do - -- diagnostic_signs[vim.diagnostic.severity[type]] = icon - -- end - -- vim.diagnostic.config { signs = { text = diagnostic_signs } } - -- end - - -- LSP servers and clients are able to communicate to each other what features they support. - -- By default, Neovim doesn't support everything that is in the LSP specification. - -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities. - -- So, we create new capabilities with nvim cmp, and then broadcast that to the servers. - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities()) - - -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- - -- Add any additional override configuration in the following tables. Available keys are: - -- - cmd (table): Override the default command used to start the server - -- - filetypes (table): Override the default list of associated filetypes for the server - -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. - -- - settings (table): Override the default settings passed when initializing the server. - -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ - local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- But for many setups, the LSP (`ts_ls`) will work just fine - -- ts_ls = {}, - -- - - lua_ls = { - -- cmd = { ... }, - -- filetypes = { ... }, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, - }, - } - - -- Ensure the servers and tools above are installed - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason - -- - -- You can press `g?` for help in this menu. - require('mason').setup() - - -- You can add other tools here that you want Mason to install - -- for you, so that they are available from within Neovim. - local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { - 'stylua', -- Used to format Lua code - }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } - end, - }, - - { -- Autoformat - 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, - keys = { - { - 'f', - function() - require('conform').format { async = true, lsp_format = 'fallback' } - end, - mode = '', - desc = '[F]ormat buffer', - }, - }, - opts = { - notify_on_error = false, - format_on_save = function(bufnr) - -- Disable "format_on_save lsp_fallback" for languages that don't - -- have a well standardized coding style. You can add additional - -- languages here or re-enable it for the disabled ones. - local disable_filetypes = { c = true, cpp = true } - local lsp_format_opt - if disable_filetypes[vim.bo[bufnr].filetype] then - lsp_format_opt = 'never' - else - lsp_format_opt = 'fallback' - end - return { - timeout_ms = 500, - lsp_format = lsp_format_opt, - } - end, - formatters_by_ft = { - lua = { 'stylua' }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, - }, - }, - }, - - { -- Autocompletion - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - { - 'L3MON4D3/LuaSnip', - build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. - if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then - return - end - return 'make install_jsregexp' - end)(), - dependencies = { - -- `friendly-snippets` contains a variety of premade snippets. - -- See the README about individual language/framework/plugin snippets: - -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, - }, - }, - 'saadparwaiz1/cmp_luasnip', - - -- Adds other completion capabilities. - -- nvim-cmp does not ship with all sources by default. They are split - -- into multiple repos for maintenance purposes. - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-path', - }, - config = function() - -- See `:help cmp` - local cmp = require 'cmp' - local luasnip = require 'luasnip' - luasnip.config.setup {} - - cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - completion = { completeopt = 'menu,menuone,noinsert' }, - - -- For an understanding of why these mappings were - -- chosen, you will need to read `:help ins-completion` - -- - -- No, but seriously. Please read `:help ins-completion`, it is really good! - mapping = cmp.mapping.preset.insert { - -- Select the [n]ext item - [''] = cmp.mapping.select_next_item(), - -- Select the [p]revious item - [''] = cmp.mapping.select_prev_item(), - - -- Scroll the documentation window [b]ack / [f]orward - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - - -- Accept ([y]es) the completion. - -- This will auto-import if your LSP supports it. - -- This will expand snippets if the LSP sent a snippet. - [''] = cmp.mapping.confirm { select = true }, - - -- If you prefer more traditional completion keymaps, - -- you can uncomment the following lines - --[''] = cmp.mapping.confirm { select = true }, - --[''] = cmp.mapping.select_next_item(), - --[''] = cmp.mapping.select_prev_item(), - - -- Manually trigger a completion from nvim-cmp. - -- Generally you don't need this, because nvim-cmp will display - -- completions whenever it has completion options available. - [''] = cmp.mapping.complete {}, - - -- Think of as moving to the right of your snippet expansion. - -- So if you have a snippet that's like: - -- function $name($args) - -- $body - -- end - -- - -- will move you to the right of each of the expansion locations. - -- is similar, except moving you backwards. - [''] = cmp.mapping(function() - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - end - end, { 'i', 's' }), - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps - }, - sources = { - { - name = 'lazydev', - -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it - group_index = 0, - }, - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'path' }, - }, - } - end, - }, - - { -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command in the config to whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() - -- Load the colorscheme here. - -- Like many other themes, this one has different styles, and you could load - -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' - - -- You can configure highlights by doing something like: - vim.cmd.hi 'Comment gui=none' - end, - }, - - -- Highlight todo, notes, etc in comments - { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, - - { -- Collection of various small independent plugins/modules - 'echasnovski/mini.nvim', - config = function() - -- Better Around/Inside textobjects - -- - -- Examples: - -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote - -- - ci' - [C]hange [I]nside [']quote - require('mini.ai').setup { n_lines = 500 } - - -- Add/delete/replace surroundings (brackets, quotes, etc.) - -- - -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren - -- - sd' - [S]urround [D]elete [']quotes - -- - sr)' - [S]urround [R]eplace [)] ['] - require('mini.surround').setup() - - -- Simple and easy statusline. - -- You could remove this setup call if you don't like it, - -- and try some other statusline plugin - local statusline = require 'mini.statusline' - -- set use_icons to true if you have a Nerd Font - statusline.setup { use_icons = vim.g.have_nerd_font } - - -- You can configure sections in the statusline by overriding their - -- default behavior. For example, here we set the section for - -- cursor location to LINE:COLUMN - ---@diagnostic disable-next-line: duplicate-set-field - statusline.section_location = function() - return '%2l:%-2v' - end - - -- ... and there is more! - -- Check out: https://github.com/echasnovski/mini.nvim - end, - }, - { -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', - main = 'nvim-treesitter.configs', -- Sets main module to use for opts - -- [[ Configure Treesitter ]] See `:help nvim-treesitter` - opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. - additional_vim_regex_highlighting = { 'ruby' }, - }, - indent = { enable = true, disable = { 'ruby' } }, - }, - -- There are additional nvim-treesitter modules that you can use to interact - -- with nvim-treesitter. You should go explore a few and see what interests you: - -- - -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` - -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects - }, - - -- The following comments only work if you have downloaded the kickstart repo, not just copy pasted the - -- init.lua. If you want these files, they are in the repository, so you can just download them and - -- place them in the correct locations. - - -- NOTE: Next step on your Neovim journey: Add/Configure additional plugins for Kickstart - -- - -- Here are some example plugins that I've included in the Kickstart repository. - -- Uncomment any of the lines below to enable them (you will need to restart nvim). - -- - -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', - -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps - - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- This is the easiest way to modularize your config. - -- - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, - -- - -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` - -- Or use telescope! - -- In normal mode type `sh` then write `lazy.nvim-plugin` - -- you can continue same window with `sr` which resumes last telescope search -}, { +require('lazy').setup({ plugins }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the -- default lazy.nvim defined Nerd Font icons, otherwise define a unicode icons table diff --git a/lua/core/keymaps/core.lua b/lua/core/keymaps/core.lua new file mode 100644 index 00000000000..643fc8d03d1 --- /dev/null +++ b/lua/core/keymaps/core.lua @@ -0,0 +1,36 @@ +---@diagnostic disable: undefined-global +-- Core Neovim keymaps (non-plugin) + +return { + -- Quick access to find files by content + { mode = 'n', lhs = '', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search text in all files' } }, + + -- Clear highlights on search + { mode = 'n', lhs = '', rhs = 'nohlsearch', opts = { desc = 'Clear search highlights' } }, + + -- Exit terminal mode + { mode = 't', lhs = '', rhs = '', opts = { desc = 'Exit terminal mode' } }, + + -- Window navigation (Ctrl + hjkl) + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window left' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window right' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window down' } }, + { mode = 'n', lhs = '', rhs = '', opts = { desc = 'Focus: Window up' } }, + + -- Window resizing (Ctrl + Arrow keys) + { mode = 'n', lhs = '', rhs = 'resize +2', opts = { desc = 'Window: Increase height' } }, + { mode = 'n', lhs = '', rhs = 'resize -2', opts = { desc = 'Window: Decrease height' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize -2', opts = { desc = 'Window: Decrease width' } }, + { mode = 'n', lhs = '', rhs = 'vertical resize +2', opts = { desc = 'Window: Increase width' } }, + + -- Move lines up and down (Alt + jk) + { mode = 'n', lhs = '', rhs = ':m .+1==', opts = { desc = 'Move line down', silent = true } }, + { mode = 'n', lhs = '', rhs = ':m .-2==', opts = { desc = 'Move line up', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '>+1gv=gv", opts = { desc = 'Move selection down', silent = true } }, + { mode = 'v', lhs = '', rhs = ":m '<-2gv=gv", opts = { desc = 'Move selection up', silent = true } }, + + -- Quick save and quit + { mode = 'n', lhs = 'w', rhs = 'w', opts = { desc = 'Save file' } }, + { mode = 'n', lhs = 'W', rhs = 'wa', opts = { desc = 'Save all files' } }, + { mode = 'n', lhs = 'Q', rhs = 'qa', opts = { desc = 'Quit all' } }, +} diff --git a/lua/core/keymaps/diagnostic.lua b/lua/core/keymaps/diagnostic.lua new file mode 100644 index 00000000000..c561cd23712 --- /dev/null +++ b/lua/core/keymaps/diagnostic.lua @@ -0,0 +1,13 @@ +---@diagnostic disable: undefined-global +-- Diagnostic keymaps + +return { + -- Navigation + { mode = 'n', lhs = '[d', rhs = vim.diagnostic.goto_prev, opts = { desc = 'Diagnostic: Previous' } }, + { mode = 'n', lhs = ']d', rhs = vim.diagnostic.goto_next, opts = { desc = 'Diagnostic: Next' } }, + + -- Viewing diagnostics + { mode = 'n', lhs = 'tt', rhs = vim.diagnostic.open_float, opts = { desc = 'Diagnostic: Show details in float' } }, + { mode = 'n', lhs = 'tl', rhs = vim.diagnostic.setloclist, opts = { desc = 'Diagnostic: Show list' } }, + { mode = 'n', lhs = 'td', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Diagnostic: Search all diagnostics' } }, +} diff --git a/lua/core/keymaps/git.lua b/lua/core/keymaps/git.lua new file mode 100644 index 00000000000..a269fa12df8 --- /dev/null +++ b/lua/core/keymaps/git.lua @@ -0,0 +1,37 @@ +---@diagnostic disable: undefined-global +-- Git keymaps + +local M = {} + +M.keymaps = { + -- Navigation + { mode = 'n', lhs = ']c', rhs = function() + if vim.wo.diff then return ']c' end + vim.schedule(function() require('gitsigns').next_hunk() end) + return '' + end, opts = { desc = 'Git: Next hunk', expr = true } }, + + { mode = 'n', lhs = '[c', rhs = function() + if vim.wo.diff then return '[c' end + vim.schedule(function() require('gitsigns').prev_hunk() end) + return '' + end, opts = { desc = 'Git: Previous hunk', expr = true } }, + + -- Actions + { mode = 'n', lhs = 'gh', rhs = function() require('gitsigns').preview_hunk() end, opts = { desc = 'Git: Preview hunk' } }, + { mode = 'n', lhs = 'gb', rhs = function() require('gitsigns').blame_line() end, opts = { desc = 'Git: Blame line' } }, + { mode = 'n', lhs = 'gd', rhs = function() require('gitsigns').diffthis() end, opts = { desc = 'Git: Show diff' } }, + { mode = { 'n', 'v' }, lhs = 'gs', rhs = function() require('gitsigns').stage_hunk() end, opts = { desc = 'Git: Stage hunk' } }, + { mode = { 'n', 'v' }, lhs = 'gr', rhs = function() require('gitsigns').reset_hunk() end, opts = { desc = 'Git: Reset hunk' } }, + { mode = 'n', lhs = 'gS', rhs = function() require('gitsigns').stage_buffer() end, opts = { desc = 'Git: Stage buffer' } }, + { mode = 'n', lhs = 'gu', rhs = function() require('gitsigns').undo_stage_hunk() end, opts = { desc = 'Git: Undo stage' } }, + { mode = 'n', lhs = 'gR', rhs = function() require('gitsigns').reset_buffer() end, opts = { desc = 'Git: Reset buffer' } }, +} + +function M.setup() + for _, mapping in ipairs(M.keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +return M diff --git a/lua/core/keymaps/init.lua b/lua/core/keymaps/init.lua new file mode 100644 index 00000000000..773b0463b19 --- /dev/null +++ b/lua/core/keymaps/init.lua @@ -0,0 +1,119 @@ +---@diagnostic disable: undefined-global +-- Keymaps init - loads all keymap modules + +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +local M = {} + +-- Import keymap modules +local core = require('core.keymaps.core') +local lsp = require('core.keymaps.lsp') +local telescope = require('core.keymaps.telescope') +local diagnostic = require('core.keymaps.diagnostic') +local git = require('core.keymaps.git') +local plugins = require('core.keymaps.plugins') + +-- Export for external use +M.setup_lsp_keymaps = lsp.setup +M.telescope_keymaps = telescope +M.diagnostic_keymaps = diagnostic +M.gitsigns_keymaps = git.keymaps +M.dadbod_keymaps = plugins.dadbod +M.session_keymaps = plugins.session +M.scratch_keymaps = plugins.scratch +M.snacks_keymaps = plugins.snacks +M.leap_keymaps = plugins.leap +M.mini_surround_keymaps = plugins.mini_surround + +-- Setup functions +M.setup_gitsigns_keymaps = git.setup +M.setup_dadbod_keymaps = plugins.setup_dadbod +M.setup_session_keymaps = plugins.setup_session +M.setup_leap_keymaps = plugins.setup_leap + +-- Default on_attach for LSP (used by lsp/setup.lua) +M.default_on_attach = nil + +local explorer_keymaps_set = false +local function setup_explorer_keymaps() + if explorer_keymaps_set then return end + explorer_keymaps_set = true + + for _, key in ipairs({ 'e', 'E' }) do + pcall(vim.keymap.del, 'n', key) + end + + for _, mapping in ipairs(plugins.snacks) do + if mapping.lhs == 'e' or mapping.lhs == 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { + replace_keycodes = false, + nowait = true, + silent = true, + })) + end + end +end + +local function init_keymaps() + local keymap_group = vim.api.nvim_create_augroup('custom_keymaps', { clear = true }) + + -- Handle snacks explorer during buffer writes + vim.api.nvim_create_autocmd({ 'BufWritePre' }, { + group = keymap_group, + callback = function() + pcall(function() + local picker = require('plugins.snacks.picker') + if picker.is_open() then + picker.pause_updates() + vim.schedule(function() picker.resume_updates() end) + end + end) + end, + }) + + -- Set up autocmds to maintain explorer keymaps + vim.api.nvim_create_autocmd({ 'VimEnter', 'BufEnter' }, { + group = keymap_group, + callback = setup_explorer_keymaps, + }) + + -- Set up LSP keymaps on attach + vim.api.nvim_create_autocmd('LspAttach', { + group = keymap_group, + callback = function(args) M.setup_lsp_keymaps(args.buf) end, + }) + + -- Core keymaps + for _, mapping in ipairs(core) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Telescope keymaps + for _, mapping in ipairs(telescope) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Diagnostic keymaps + for _, mapping in ipairs(diagnostic) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Plugin keymaps + plugins.setup_snacks() + plugins.setup_scratch() + plugins.setup_dadbod() + plugins.setup_session() + plugins.setup_leap() + git.setup() + + -- Tab navigation + vim.keymap.set('n', 'gt', ':tabnext', { silent = true, desc = 'Next tab' }) + vim.keymap.set('n', 'gT', ':tabprevious', { silent = true, desc = 'Previous tab' }) +end + +init_keymaps() + +M.setup = init_keymaps + +return M diff --git a/lua/core/keymaps/lsp.lua b/lua/core/keymaps/lsp.lua new file mode 100644 index 00000000000..76e0af31ff3 --- /dev/null +++ b/lua/core/keymaps/lsp.lua @@ -0,0 +1,70 @@ +---@diagnostic disable: undefined-global +-- LSP keymaps + +local M = {} + +function M.setup(bufnr) + local keymaps = { + -- Go to definitions + { mode = 'n', lhs = 'gd', rhs = function() require('telescope.builtin').lsp_definitions() end, opts = { desc = 'LSP: Go to definition' } }, + { mode = 'n', lhs = 'gr', rhs = function() require('telescope.builtin').lsp_references() end, opts = { desc = 'LSP: Find references' } }, + { mode = 'n', lhs = 'gI', rhs = function() require('telescope.builtin').lsp_implementations() end, opts = { desc = 'LSP: Go to implementation' } }, + { mode = 'n', lhs = 'gy', rhs = function() require('telescope.builtin').lsp_type_definitions() end, opts = { desc = 'LSP: Go to type definition' } }, + + -- Symbol navigation + { mode = 'n', lhs = 'ls', rhs = function() + require('telescope.builtin').lsp_document_symbols({ position_encoding = 'utf-16' }) + end, opts = { desc = 'LSP: Document symbols' } }, + { mode = 'n', lhs = 'lS', rhs = function() + local status_ok, _ = pcall(function() + require('telescope.builtin').lsp_dynamic_workspace_symbols({ + position_encoding = 'utf-16', + show_line = true, + fname_width = 50, + symbol_width = 35, + attach_mappings = function(prompt_bufnr) + require("telescope.actions").select_default:replace(function() + local entry = require("telescope.actions.state").get_selected_entry() + if not entry then return end + require("telescope.actions").close(prompt_bufnr) + if entry.value and entry.value.filename then + vim.cmd(string.format('edit %s', entry.value.filename)) + vim.api.nvim_win_set_cursor(0, {entry.value.lnum, entry.value.col}) + end + end) + return true + end + }) + end) + if not status_ok then + vim.notify("Workspace symbols not available for this language server", vim.log.levels.INFO) + end + end, opts = { desc = 'LSP: Workspace symbols' } }, + + -- Code actions + { mode = 'n', lhs = 'lr', rhs = vim.lsp.buf.rename, opts = { desc = 'LSP: Rename symbol' } }, + { mode = 'n', lhs = 'la', rhs = vim.lsp.buf.code_action, opts = { desc = 'LSP: Code action' } }, + { mode = 'n', lhs = 'lf', rhs = function() vim.lsp.buf.format({ async = true }) end, opts = { desc = 'LSP: Format code' } }, + + -- Documentation + { mode = 'n', lhs = 'K', rhs = function() require('hover').hover() end, opts = { desc = 'Enhanced documentation (hover.nvim)' } }, + } + + -- Clear existing LSP keymaps for this buffer + local lsp_maps = { 'gd', 'gr', 'gI', 'gy', 'K', 'ls', 'lS', 'lr', 'la', 'lf' } + for _, lhs in ipairs(lsp_maps) do + pcall(vim.keymap.del, 'n', lhs, { buffer = bufnr }) + end + + -- Set keymaps with buffer local + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, vim.tbl_extend('force', mapping.opts, { + buffer = bufnr, + replace_keycodes = false, + nowait = true, + silent = true, + })) + end +end + +return M diff --git a/lua/core/keymaps/plugins.lua b/lua/core/keymaps/plugins.lua new file mode 100644 index 00000000000..278d1bf75b4 --- /dev/null +++ b/lua/core/keymaps/plugins.lua @@ -0,0 +1,107 @@ +---@diagnostic disable: undefined-global +-- Plugin keymaps (dadbod, session, scratch, snacks, leap, mini-surround) + +local M = {} + +-- Database keymaps +M.dadbod = { + { mode = 'n', lhs = 'Dt', rhs = 'DBUIToggle', opts = { desc = 'Database: Toggle UI' } }, + { mode = 'n', lhs = 'Df', rhs = 'DBUIFindBuffer', opts = { desc = 'Database: Find buffer' } }, + { mode = 'n', lhs = 'Dr', rhs = 'DBUIRenameBuffer', opts = { desc = 'Database: Rename buffer' } }, + { mode = 'n', lhs = 'Dl', rhs = 'DBUILastQueryInfo', opts = { desc = 'Database: Last query' } }, +} + +-- Session keymaps +M.session = { + { mode = 'n', lhs = 'mw', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').write(name, { force = true }) + end, opts = { desc = 'Memory: Write session' } }, + { mode = 'n', lhs = 'mr', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').read(name) + end, opts = { desc = 'Memory: Read session' } }, + { mode = 'n', lhs = 'md', rhs = function() + local name = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + require('mini.sessions').delete(name) + end, opts = { desc = 'Memory: Delete session' } }, +} + +-- Scratch buffer keymaps +M.scratch = { + { mode = 'n', lhs = '.', rhs = function() require("snacks").scratch() end, opts = { desc = 'Toggle scratch buffer' } }, + { mode = 'n', lhs = 'S', rhs = function() require("snacks").scratch.select() end, opts = { desc = 'Select scratch buffer' } }, + { mode = 'n', lhs = 'nh', rhs = function() require("snacks.notifier").show_history() end, opts = { desc = 'Show notification history' } }, +} + +-- Snacks keymaps (explorer and terminal) +M.snacks = { + { mode = 'n', lhs = 'e', rhs = function() require('snacks').explorer.open() end, opts = { desc = 'Explorer: Toggle' } }, + { mode = 'n', lhs = 'E', rhs = function() require('snacks').explorer.reveal() end, opts = { desc = 'Explorer: Focus current file' } }, + { mode = 'n', lhs = 'o', rhs = function() vim.cmd('tab split %') end, opts = { desc = 'Open current file in new tab' } }, + { mode = 'n', lhs = 'f', rhs = function() + vim.cmd('tabnew') + require('snacks').explorer.open() + end, opts = { desc = 'Explorer: Open in new tab' } }, + { mode = 'n', lhs = '', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle float window' } }, + { mode = 'n', lhs = 'tc', rhs = function() require('snacks').terminal.toggle() end, opts = { desc = 'Terminal: Toggle console' } }, +} + +-- Leap keymaps +M.leap = { + { mode = { 'n', 'x', 'o' }, lhs = 's', rhs = function() require('leap').leap {} end, opts = { desc = 'Leap: Search bidirectional' } }, + { mode = { 'n', 'x', 'o' }, lhs = 'S', rhs = function() + require('leap').leap { target_windows = vim.tbl_filter( + function (win) return vim.api.nvim_win_get_config(win).focusable end, + vim.api.nvim_tabpage_list_wins(0) + )} + end, opts = { desc = 'Leap: Search across windows' } }, +} + +-- Mini-surround keymaps (used by mini.surround config) +M.mini_surround = { + add = 'sa', + delete = 'sd', + find = 'sf', + find_left = 'sF', + highlight = 'sh', + replace = 'sr', + update_n_lines = '', + suffix_last = 'l', + suffix_next = 'n', +} + +-- Setup functions +function M.setup_dadbod() + for _, mapping in ipairs(M.dadbod) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_session() + for _, mapping in ipairs(M.session) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_scratch() + for _, mapping in ipairs(M.scratch) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +function M.setup_snacks() + for _, mapping in ipairs(M.snacks) do + if mapping.lhs ~= 'e' and mapping.lhs ~= 'E' then + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + end +end + +function M.setup_leap() + for _, mapping in ipairs(M.leap) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end +end + +return M diff --git a/lua/core/keymaps/telescope.lua b/lua/core/keymaps/telescope.lua new file mode 100644 index 00000000000..4ee6f44fbc6 --- /dev/null +++ b/lua/core/keymaps/telescope.lua @@ -0,0 +1,32 @@ +---@diagnostic disable: undefined-global +-- Telescope keymaps + +return { + -- Help + { mode = 'n', lhs = 'sh', rhs = function() require('telescope.builtin').help_tags() end, opts = { desc = 'Search: Help' } }, + { mode = 'n', lhs = 'sk', rhs = function() require('telescope.builtin').keymaps() end, opts = { desc = 'Search: Keymaps' } }, + + -- Files + { mode = 'n', lhs = 'sf', rhs = function() require('telescope.builtin').find_files() end, opts = { desc = 'Search: Files' } }, + { mode = 'n', lhs = 'sr', rhs = function() require('telescope.builtin').oldfiles() end, opts = { desc = 'Search: Recent files' } }, + + -- Text + { mode = 'n', lhs = 'sg', rhs = function() require('telescope.builtin').live_grep() end, opts = { desc = 'Search: Text in workspace' } }, + { mode = 'n', lhs = 'sw', rhs = function() require('telescope.builtin').grep_string() end, opts = { desc = 'Search: Word under cursor' } }, + { mode = 'n', lhs = '/', rhs = function() + require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) + end, opts = { desc = 'Search: Text in buffer' } }, + { mode = 'n', lhs = 's/', rhs = function() + require('telescope.builtin').live_grep { + grep_open_files = true, + prompt_title = 'Live Grep in Open Files', + } + end, opts = { desc = 'Search: Text in open files' } }, + + -- Workspace + { mode = 'n', lhs = 'sd', rhs = function() require('telescope.builtin').diagnostics() end, opts = { desc = 'Search: Diagnostics' } }, + { mode = 'n', lhs = 'sb', rhs = function() require('telescope.builtin').buffers() end, opts = { desc = 'Search: Buffers' } }, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua deleted file mode 100644 index be0eb9d8d7a..00000000000 --- a/lua/custom/plugins/init.lua +++ /dev/null @@ -1,5 +0,0 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} diff --git a/lua/kickstart/health.lua b/lua/kickstart/health.lua deleted file mode 100644 index b59d08649af..00000000000 --- a/lua/kickstart/health.lua +++ /dev/null @@ -1,52 +0,0 @@ ---[[ --- --- This file is not required for your own configuration, --- but helps people determine if their system is setup correctly. --- ---]] - -local check_version = function() - local verstr = tostring(vim.version()) - if not vim.version.ge then - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) - return - end - - if vim.version.ge(vim.version(), '0.10-dev') then - vim.health.ok(string.format("Neovim version is: '%s'", verstr)) - else - vim.health.error(string.format("Neovim out of date: '%s'. Upgrade to latest stable or nightly", verstr)) - end -end - -local check_external_reqs = function() - -- Basic utils: `git`, `make`, `unzip` - for _, exe in ipairs { 'git', 'make', 'unzip', 'rg' } do - local is_executable = vim.fn.executable(exe) == 1 - if is_executable then - vim.health.ok(string.format("Found executable: '%s'", exe)) - else - vim.health.warn(string.format("Could not find executable: '%s'", exe)) - end - end - - return true -end - -return { - check = function() - vim.health.start 'kickstart.nvim' - - vim.health.info [[NOTE: Not every warning is a 'must-fix' in `:checkhealth` - - Fix only warnings for plugins and languages you intend to use. - Mason will give warnings for languages that are not installed. - You do not need to install, unless you want to use those languages!]] - - local uv = vim.uv or vim.loop - vim.health.info('System Information: ' .. vim.inspect(uv.os_uname())) - - check_version() - check_external_reqs() - end, -} diff --git a/lua/kickstart/plugins/autopairs.lua b/lua/kickstart/plugins/autopairs.lua deleted file mode 100644 index 87a7e5ffa2e..00000000000 --- a/lua/kickstart/plugins/autopairs.lua +++ /dev/null @@ -1,16 +0,0 @@ --- autopairs --- https://github.com/windwp/nvim-autopairs - -return { - 'windwp/nvim-autopairs', - event = 'InsertEnter', - -- Optional dependency - dependencies = { 'hrsh7th/nvim-cmp' }, - config = function() - require('nvim-autopairs').setup {} - -- If you want to automatically add `(` after selecting a function or method - local cmp_autopairs = require 'nvim-autopairs.completion.cmp' - local cmp = require 'cmp' - cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) - end, -} diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua deleted file mode 100644 index 753cb0cedd3..00000000000 --- a/lua/kickstart/plugins/debug.lua +++ /dev/null @@ -1,148 +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', - }, - keys = { - -- Basic debugging keymaps, feel free to change to your liking! - { - '', - function() - require('dap').continue() - end, - desc = 'Debug: Start/Continue', - }, - { - '', - function() - require('dap').step_into() - end, - desc = 'Debug: Step Into', - }, - { - '', - function() - require('dap').step_over() - end, - desc = 'Debug: Step Over', - }, - { - '', - function() - require('dap').step_out() - end, - desc = 'Debug: Step Out', - }, - { - 'b', - 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', - }, - } - - -- 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, - }, - } - end, -} diff --git a/lua/kickstart/plugins/gitsigns.lua b/lua/kickstart/plugins/gitsigns.lua deleted file mode 100644 index c269bc06e15..00000000000 --- a/lua/kickstart/plugins/gitsigns.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Adds git related signs to the gutter, as well as utilities for managing changes --- NOTE: gitsigns is already included in init.lua but contains only the base --- config. This will add also the recommended keymaps. - -return { - { - 'lewis6991/gitsigns.nvim', - opts = { - on_attach = function(bufnr) - local gitsigns = require 'gitsigns' - - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end - - -- Navigation - map('n', ']c', function() - if vim.wo.diff then - vim.cmd.normal { ']c', bang = true } - else - gitsigns.nav_hunk 'next' - end - end, { desc = 'Jump to next git [c]hange' }) - - map('n', '[c', function() - if vim.wo.diff then - vim.cmd.normal { '[c', bang = true } - else - gitsigns.nav_hunk 'prev' - end - end, { desc = 'Jump to previous git [c]hange' }) - - -- Actions - -- visual mode - map('v', 'hs', function() - gitsigns.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'git [s]tage hunk' }) - map('v', 'hr', function() - gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } - end, { desc = 'git [r]eset hunk' }) - -- normal mode - map('n', 'hs', gitsigns.stage_hunk, { desc = 'git [s]tage hunk' }) - map('n', 'hr', gitsigns.reset_hunk, { desc = 'git [r]eset hunk' }) - map('n', 'hS', gitsigns.stage_buffer, { desc = 'git [S]tage buffer' }) - map('n', 'hu', gitsigns.undo_stage_hunk, { desc = 'git [u]ndo stage hunk' }) - map('n', 'hR', gitsigns.reset_buffer, { desc = 'git [R]eset buffer' }) - map('n', 'hp', gitsigns.preview_hunk, { desc = 'git [p]review hunk' }) - map('n', 'hb', gitsigns.blame_line, { desc = 'git [b]lame line' }) - map('n', 'hd', gitsigns.diffthis, { desc = 'git [d]iff against index' }) - map('n', 'hD', function() - gitsigns.diffthis '@' - end, { desc = 'git [D]iff against last commit' }) - -- Toggles - map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = '[T]oggle git show [b]lame line' }) - map('n', 'tD', gitsigns.toggle_deleted, { desc = '[T]oggle git show [D]eleted' }) - end, - }, - }, -} diff --git a/lua/kickstart/plugins/indent_line.lua b/lua/kickstart/plugins/indent_line.lua deleted file mode 100644 index ed7f269399f..00000000000 --- a/lua/kickstart/plugins/indent_line.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - { -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help ibl` - main = 'ibl', - opts = {}, - }, -} diff --git a/lua/kickstart/plugins/lint.lua b/lua/kickstart/plugins/lint.lua deleted file mode 100644 index 907c6bf3e31..00000000000 --- a/lua/kickstart/plugins/lint.lua +++ /dev/null @@ -1,60 +0,0 @@ -return { - - { -- Linting - 'mfussenegger/nvim-lint', - event = { 'BufReadPre', 'BufNewFile' }, - config = function() - local lint = require 'lint' - lint.linters_by_ft = { - markdown = { 'markdownlint' }, - } - - -- To allow other plugins to add linters to require('lint').linters_by_ft, - -- instead set linters_by_ft like this: - -- lint.linters_by_ft = lint.linters_by_ft or {} - -- lint.linters_by_ft['markdown'] = { 'markdownlint' } - -- - -- However, note that this will enable a set of default linters, - -- which will cause errors unless these tools are available: - -- { - -- clojure = { "clj-kondo" }, - -- dockerfile = { "hadolint" }, - -- inko = { "inko" }, - -- janet = { "janet" }, - -- json = { "jsonlint" }, - -- markdown = { "vale" }, - -- rst = { "vale" }, - -- ruby = { "ruby" }, - -- terraform = { "tflint" }, - -- text = { "vale" } - -- } - -- - -- You can disable the default linters by setting their filetypes to nil: - -- lint.linters_by_ft['clojure'] = nil - -- lint.linters_by_ft['dockerfile'] = nil - -- lint.linters_by_ft['inko'] = nil - -- lint.linters_by_ft['janet'] = nil - -- lint.linters_by_ft['json'] = nil - -- lint.linters_by_ft['markdown'] = nil - -- lint.linters_by_ft['rst'] = nil - -- lint.linters_by_ft['ruby'] = nil - -- lint.linters_by_ft['terraform'] = nil - -- lint.linters_by_ft['text'] = nil - - -- Create autocommand which carries out the actual linting - -- on the specified events. - local lint_augroup = vim.api.nvim_create_augroup('lint', { clear = true }) - vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, { - group = lint_augroup, - callback = function() - -- Only run the linter in buffers that you can modify in order to - -- avoid superfluous noise, notably within the handy LSP pop-ups that - -- describe the hovered symbol using Markdown. - if vim.opt_local.modifiable:get() then - lint.try_lint() - end - end, - }) - end, - }, -} diff --git a/lua/kickstart/plugins/neo-tree.lua b/lua/kickstart/plugins/neo-tree.lua deleted file mode 100644 index bd4422695aa..00000000000 --- a/lua/kickstart/plugins/neo-tree.lua +++ /dev/null @@ -1,25 +0,0 @@ --- Neo-tree is a Neovim plugin to browse the file system --- https://github.com/nvim-neo-tree/neo-tree.nvim - -return { - 'nvim-neo-tree/neo-tree.nvim', - version = '*', - dependencies = { - 'nvim-lua/plenary.nvim', - 'nvim-tree/nvim-web-devicons', -- not strictly required, but recommended - 'MunifTanjim/nui.nvim', - }, - cmd = 'Neotree', - keys = { - { '\\', ':Neotree reveal', desc = 'NeoTree reveal', silent = true }, - }, - opts = { - filesystem = { - window = { - mappings = { - ['\\'] = 'close_window', - }, - }, - }, - }, -} diff --git a/lua/options/autocmds.lua b/lua/options/autocmds.lua new file mode 100644 index 00000000000..c641ff30db8 --- /dev/null +++ b/lua/options/autocmds.lua @@ -0,0 +1,60 @@ +---@diagnostic disable: undefined-global +local M = {} + +function M.setup() + -- Highlight when yanking (copying) text + vim.api.nvim_create_autocmd('TextYankPost', { + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, + }) + + + -- Fix for zig.vim ftplugin error - cache zig env result + vim.api.nvim_create_autocmd('FileType', { + pattern = 'zig', + group = vim.api.nvim_create_augroup('user-zig-fix', { clear = true }), + callback = function() + if vim.fn.executable('zig') ~= 1 or vim.g.zig_std_dir then return end + + -- Single popen call - try JSON first (newer zig), fallback to struct parsing + local handle = io.popen('zig env 2>/dev/null') + if not handle then return end + + local result = handle:read('*a') + handle:close() + + -- Try JSON parse first + local success, env = pcall(vim.fn.json_decode, result) + if success and type(env) == 'table' and env.std_dir then + vim.g.zig_std_dir = env.std_dir + else + -- Fallback: extract from struct output + vim.g.zig_std_dir = result:match('%.std_dir%s*=%s*"([^"]+)"') + end + + if vim.g.zig_std_dir then + vim.opt_local.path:prepend(vim.g.zig_std_dir) + end + end, + }) + + vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*', + callback = function(args) + local bufnr = args.buf + -- Check if null-ls is the formatter for this buffer + local client = vim.lsp.get_clients({ name = 'null-ls', bufnr = bufnr })[1] + if not client then + return + end + + -- Format the buffer + vim.lsp.buf.format({ bufnr = bufnr, filter = function(c) return c.name == 'null-ls' end, async = false }) + end, + }) +end + +return M diff --git a/lua/options/gitsigns.lua b/lua/options/gitsigns.lua new file mode 100644 index 00000000000..4f5441c7f9a --- /dev/null +++ b/lua/options/gitsigns.lua @@ -0,0 +1,12 @@ +return { -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '_' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + }, + }, +} diff --git a/lua/options/settings.lua b/lua/options/settings.lua new file mode 100644 index 00000000000..270e4515a62 --- /dev/null +++ b/lua/options/settings.lua @@ -0,0 +1,112 @@ +-- [[ Setting options ]] +-- See `:help vim.opt` +-- NOTE: You can change these options as you wish! +-- For more options, you can see `:help option-list` + +---@diagnostic disable: undefined-global +-- Make line numbers default +vim.opt.number = true +vim.opt.relativenumber = true +-- You can also add relative line numbers, to help with jumping. +-- Experiment for yourself to see if you like it! +-- vim.opt.relativenumber = true + +-- Enable mouse mode, can be useful for resizing splits for example! +vim.opt.mouse = 'a' + +-- Don't show the mode, since it's already in the status line +vim.opt.showmode = false + +-- Sync clipboard between OS and Neovim. +-- Schedule the setting after `UiEnter` because it can increase startup-time. +-- Remove this option if you want your OS clipboard to remain independent. +-- See `:help 'clipboard'` +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + +-- Enable break indent +vim.opt.breakindent = true + +-- Save undo history +vim.opt.undofile = true + +-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- Keep signcolumn on by default +vim.opt.signcolumn = 'yes' + +-- Decrease update time +vim.opt.updatetime = 250 + +-- Decrease mapped sequence wait time +vim.opt.timeoutlen = 300 + +-- Configure how new splits should be opened +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- Disable word wrap +vim.opt.wrap = false + +-- Sets how neovim will display certain whitespace characters in the editor. +-- See `:help 'list'` +-- and `:help 'listchars'` +vim.opt.list = true +-- Do not set 'tab' in listchars so ibl can show its own indent guides +-- Use a vertical bar for tabs so ibl and listchars both show vertical guides +vim.opt.listchars = { tab = '│ ', trail = '·', nbsp = '␣' } + +-- Set tab size and convert tabs to spaces +vim.opt.tabstop = 2 -- Number of visual spaces per TAB +vim.opt.shiftwidth = 2 -- Number of spaces to use for each step of (auto)indent +vim.opt.softtabstop = 2 -- Number of spaces that a counts for while performing editing operations +vim.opt.expandtab = true -- Use spaces instead of tabs + +-- Preview substitutions live, as you type! +vim.opt.inccommand = 'split' + +-- Show which line your cursor is on +vim.opt.cursorline = true + +-- Minimal number of screen lines to keep above and below the cursor. +vim.opt.scrolloff = 10 + +-- Disable winbar +vim.opt.winbar = "" + +-- Set diagnostic signs +vim.diagnostic.config({ + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "", + [vim.diagnostic.severity.WARN] = "", + [vim.diagnostic.severity.INFO] = "", + [vim.diagnostic.severity.HINT] = "󰌵", + }, + texthl = { + [vim.diagnostic.severity.ERROR] = "DiagnosticSignError", + [vim.diagnostic.severity.WARN] = "DiagnosticSignWarn", + [vim.diagnostic.severity.INFO] = "DiagnosticSignInfo", + [vim.diagnostic.severity.HINT] = "DiagnosticSignHint", + }, + }, +}) + +-- Add module interface for settings +local M = {} + +function M.setup() + -- Ensure swapfile directory exists and configure swapfile settings + local swap_dir = vim.fn.stdpath('data') .. '/swapfiles' + if vim.fn.isdirectory(swap_dir) == 0 then + vim.fn.mkdir(swap_dir, 'p') + end + vim.opt.directory = swap_dir + vim.opt.swapfile = true + vim.opt.updatecount = 100 +end + +return M diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 00000000000..5f0ab1605ff --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,9 @@ +return { + 'akinsho/bufferline.nvim', + version = "*", + dependencies = 'nvim-tree/nvim-web-devicons', + opts = require('plugins.bufferline.setup').opts, + config = function(_, opts) + require('plugins.bufferline.setup').setup() + end, +} diff --git a/lua/plugins/bufferline/setup.lua b/lua/plugins/bufferline/setup.lua new file mode 100644 index 00000000000..7cdd189d70e --- /dev/null +++ b/lua/plugins/bufferline/setup.lua @@ -0,0 +1,61 @@ +---@diagnostic disable: undefined-global +-- bufferline setup module +local M = {} + +M.opts = { + options = { + mode = "buffers", -- set to "tabs" to only show tabpages instead of buffers + numbers = "none", + close_command = "bdelete! %d", -- can be a string | function, | false see "Mouse actions" + right_mouse_command = "bdelete! %d", -- can be a string | function | false, see "Mouse actions" + left_mouse_command = "buffer %d", -- can be a string | function, | false see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function | false see "Mouse actions" + indicator = { + icon = '▎', -- this should be omitted if indicator style is not 'icon' + style = 'icon', + }, + buffer_close_icon = '󰅖', + modified_icon = '●', + close_icon = '', + left_trunc_marker = '', + right_trunc_marker = '', + max_name_length = 30, + max_prefix_length = 30, + truncate_names = true, + tab_size = 21, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = false, + diagnostics_indicator = function(count, level, diagnostics_dict, context) + return "("..count..")" + end, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "left", + separator = true, + }, + }, + color_icons = true, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + show_duplicate_prefix = true, + persist_buffer_sort = true, + separator_style = "thin", + enforce_regular_tabs = false, + always_show_bufferline = true, + hover = { + enabled = true, + delay = 200, + reveal = {'close'}, + }, + }, +} + +function M.setup() + require('bufferline').setup(M.opts) +end + +return M diff --git a/lua/plugins/cmp/setup.lua b/lua/plugins/cmp/setup.lua new file mode 100644 index 00000000000..25ffaa9b6e6 --- /dev/null +++ b/lua/plugins/cmp/setup.lua @@ -0,0 +1,260 @@ +---@diagnostic disable: undefined-global +-- nvim-cmp setup module +local M = {} + +function M.setup() + local cmp = require 'cmp' + local luasnip = require 'luasnip' + local types = require 'cmp.types' + local compare = require 'cmp.config.compare' + luasnip.config.setup {} + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + -- Improved completion settings - more like VSCode + completion = { + completeopt = 'menu,menuone,noinsert', + keyword_length = 1, -- Show completions after 1 character + autocomplete = { types.cmp.TriggerEvent.TextChanged }, + get_trigger_characters = function(trigger_characters) + -- Always add '.' as a trigger character to ensure method/property completions + if not vim.tbl_contains(trigger_characters, '.') then + table.insert(trigger_characters, '.') + end + if not vim.tbl_contains(trigger_characters, ':') then + table.insert(trigger_characters, ':') + end + return trigger_characters + end, + }, + -- Custom sorting to prioritize fields and methods over snippets + sorting = { + priority_weight = 10, -- Increase weight to make priority differences more significant + comparators = { + -- Custom comparator that puts snippets at the end + function(entry1, entry2) + local types = require('cmp.types') + + -- Extract the kinds + local kind1 = entry1:get_kind() + local kind2 = entry2:get_kind() + + -- Define snippet kinds + local snippet_kinds = { + [types.lsp.CompletionItemKind.Snippet] = true + } + + -- Check if either is a snippet + local is_snippet1 = snippet_kinds[kind1] or false + local is_snippet2 = snippet_kinds[kind2] or false + + -- If one is a snippet and the other isn't, the non-snippet comes first + if is_snippet1 and not is_snippet2 then + return false + elseif not is_snippet1 and is_snippet2 then + return true + end + + -- Otherwise fall through to other comparators + return nil + end, + compare.exact, -- Exact match first + compare.kind, -- Sort by kind (functions first, then properties, etc) + compare.sort_text, -- Sort by LSP's sortText + compare.score, -- Score based + compare.offset, -- Closest to cursor + compare.length, -- Shorter first + compare.order, -- Source order + }, + }, + -- Enhanced VSCode-like icons with more modern symbols + formatting = { + format = function(entry, vim_item) + -- Set icons for completion types + local kind_icons = { + Text = "󰉿", Method = "󰆧", Function = "󰊕", Constructor = "", + Field = "󰜢", Variable = "󰀫", Class = "󰠱", Interface = "", + Module = "", Property = "󰜢", Unit = "", Value = "󰎠", + Enum = "", Keyword = "󰌋", Snippet = "", Color = "󰏘", + File = "󰈙", Reference = "", Folder = "󰉋", EnumMember = "", + Constant = "󰏿", Struct = "", Event = "", Operator = "󰆕", + TypeParameter = "󰊄", TypeAlias = "", Parameter = "", StaticMethod = "", + Macro = "󰁌" + } + + -- Enhanced formatting with better icons and spacing + vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind] or '', vim_item.kind) + + -- Show more detailed source info + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[Snippet]", + path = "[Path]", + })[entry.source.name] + + return vim_item + end, + }, + -- Enhanced documentation window + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + col_offset = -3, + side_padding = 1, + }), + documentation = cmp.config.window.bordered({ + winhighlight = "Normal:CmpDoc", + }), + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + }, + -- Configure completion sources by priority with tweaked settings + sources = cmp.config.sources( + { + { name = 'nvim_lsp', priority = 1000, max_item_count = 50 }, -- LSP comes first with more items + { name = 'path', priority = 500 }, -- Then paths + { name = 'buffer', priority = 250, keyword_length = 3 }, -- Then current buffer + -- Snippets with extremely low priority and limited visibility + { name = 'luasnip', priority = 10, max_item_count = 3, keyword_length = 4 }, + } + ), + -- Enable experimental features for VSCode-like experience + experimental = { + ghost_text = true, -- Shows virtual text as preview + }, + } + + -- Cmdline completion for search (/, ?) and command (:) + -- Enhanced commandline completion with better history and formatting + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer', max_item_count = 20 } + }, + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + }) + }, + completion = { + completeopt = 'menu,menuone,noinsert', + } + }) + + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline({ + -- Explicit key mappings for command mode completion + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + cmp.select_next_item() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + cmp.select_prev_item() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + cmp.complete() + end + end, + }, + [''] = { + c = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + cmp.complete() + end + end, + }, + [''] = { + c = cmp.mapping.abort(), + }, + [''] = { + c = cmp.mapping.confirm({ select = true }), + }, + }), + sources = cmp.config.sources({ + { name = 'path', max_item_count = 20 }, + { name = 'cmdline', max_item_count = 30, keyword_length = 1 } + }), + window = { + completion = cmp.config.window.bordered({ + winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenuBorder,CursorLine:PmenuSel,Search:None", + scrollbar = true, + col_offset = -3, + side_padding = 1, + }) + }, + formatting = { + format = function(entry, vim_item) + -- Only show item kind for cmdline completion + vim_item.kind = ' ' + vim_item.menu = '' + return vim_item + end, + }, + completion = { + completeopt = 'menu,menuone,noinsert', + autocomplete = { cmp.TriggerEvent.TextChanged }, + } + }) +end + +return M diff --git a/lua/plugins/coding.lua b/lua/plugins/coding.lua new file mode 100644 index 00000000000..3b4e3809a55 --- /dev/null +++ b/lua/plugins/coding.lua @@ -0,0 +1,7 @@ +---@diagnostic disable: undefined-global +return { + require('plugins.coding.go'), + require('plugins.coding.zig'), + require('plugins.coding.clangd'), + require('plugins.coding.dap'), +} diff --git a/lua/plugins/coding/clangd.lua b/lua/plugins/coding/clangd.lua new file mode 100644 index 00000000000..19c62f258c3 --- /dev/null +++ b/lua/plugins/coding/clangd.lua @@ -0,0 +1,28 @@ +---@diagnostic disable: undefined-global +return { + "p00f/clangd_extensions.nvim", + dependencies = { "neovim/nvim-lspconfig" }, + ft = { "c", "cpp", "objc", "objcpp", "cuda", "proto" }, + opts = { + inlay_hints = { inline = false }, + ast = { + role_icons = { + type = "🄣", + declaration = "🄓", + expression = "🄔", + statement = ";", + specifier = "🄢", + ["template argument"] = "🆃", + }, + kind_icons = { + Compound = "🄲", + Recovery = "🅁", + TranslationUnit = "🅄", + PackExpansion = "🄿", + TemplateTypeParm = "🅃", + TemplateTemplateParm = "🅃", + TemplateParamObject = "🅃", + }, + }, + }, +} diff --git a/lua/plugins/coding/dap.lua b/lua/plugins/coding/dap.lua new file mode 100644 index 00000000000..3ca97094641 --- /dev/null +++ b/lua/plugins/coding/dap.lua @@ -0,0 +1,146 @@ +---@diagnostic disable: undefined-global +return { + "mfussenegger/nvim-dap", + keys = { + { "pb", desc = "Toggle [B]reakpoint" }, + { "pc", desc = "[C]ontinue debugging" }, + { "pn", desc = "Step over ([N]ext)" }, + { "pi", desc = "Step [I]nto" }, + { "po", desc = "Step [O]ut" }, + { "pr", desc = "Open [R]EPL" }, + { "pl", desc = "Run [L]ast debug session" }, + { "px", desc = "Toggle debug UI" }, + }, + dependencies = { + "rcarriga/nvim-dap-ui", + "theHamsta/nvim-dap-virtual-text", + "leoluz/nvim-dap-go", + "nvim-neotest/nvim-nio", + }, + config = function() + local dap = require("dap") + local dapui = require("dapui") + + -- Set up Go debugging + require("dap-go").setup() + + -- Set up Python debugging + dap.adapters.python = { + type = 'executable', + command = 'debugpy-adapter', + } + + dap.configurations.python = { + { + type = 'python', + request = 'launch', + name = "Launch file", + program = "${file}", + pythonPath = function() + if vim.env.VIRTUAL_ENV then + return vim.env.VIRTUAL_ENV .. "/bin/python" + end + return '/usr/bin/python3' + end, + }, + } + + -- Set up C debugging with codelldb + dap.adapters.codelldb = { + type = 'server', + port = "${port}", + executable = { + command = 'codelldb', + args = {"--port", "${port}"}, + }, + } + + dap.configurations.c = { + { + name = "Launch file", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + }, + } + + -- Set up UI + dapui.setup({ + layouts = { + { + elements = { + { id = "scopes", size = 0.25 }, + { id = "breakpoints", size = 0.25 }, + { id = "stacks", size = 0.25 }, + { id = "watches", size = 0.25 }, + }, + position = "left", + size = 40, + }, + { + elements = { + { id = "repl", size = 0.5 }, + { id = "console", size = 0.5 }, + }, + position = "bottom", + size = 10, + }, + }, + }) + + -- Automatically open/close UI on session events + 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 + + -- Add keymaps + vim.keymap.set('n', 'pb', dap.toggle_breakpoint, { desc = 'Toggle Breakpoint' }) + vim.keymap.set('n', 'pc', dap.continue, { desc = 'Continue Debug' }) + vim.keymap.set('n', 'pn', dap.step_over, { desc = 'Step Over' }) + vim.keymap.set('n', 'pi', dap.step_into, { desc = 'Step Into' }) + vim.keymap.set('n', 'po', dap.step_out, { desc = 'Step Out' }) + vim.keymap.set('n', 'pr', dap.repl.open, { desc = 'Debug REPL' }) + vim.keymap.set('n', 'pl', dap.run_last, { desc = 'Run Last Debug' }) + vim.keymap.set('n', 'px', dapui.toggle, { desc = 'Toggle Debug UI' }) + + -- Profiling commands + local function profile_go() + local file = vim.fn.expand('%:p') + local cmd = string.format('go test -cpuprofile cpu.prof -memprofile mem.prof -bench . %s', file) + vim.fn.system(cmd) + vim.cmd('split term://go tool pprof -http=:8080 cpu.prof') + end + + local function profile_python() + local file = vim.fn.expand('%:p') + local cmd = string.format('py-spy record -o profile.svg -f speedscope -- python %s', file) + vim.fn.system(cmd) + vim.cmd('!xdg-open profile.svg') + end + + local function profile_c() + local file = vim.fn.expand('%:p:r') + local cmd = string.format('perf record -g ./%s && perf report -g graph', file) + vim.cmd('split term://' .. cmd) + end + + vim.api.nvim_create_autocmd('FileType', { + pattern = { 'go', 'python', 'c', 'cpp' }, + callback = function() + local ft = vim.bo.filetype + if ft == 'go' then + vim.keymap.set('n', 'mp', profile_go, { buffer = true, desc = 'Profile Go code' }) + elseif ft == 'python' then + vim.keymap.set('n', 'mp', profile_python, { buffer = true, desc = 'Profile Python code' }) + elseif ft == 'c' or ft == 'cpp' then + vim.keymap.set('n', 'mp', profile_c, { buffer = true, desc = 'Profile C/C++ code' }) + end + end, + }) + end, +} diff --git a/lua/plugins/coding/go.lua b/lua/plugins/coding/go.lua new file mode 100644 index 00000000000..6d1b83a25ab --- /dev/null +++ b/lua/plugins/coding/go.lua @@ -0,0 +1,24 @@ +---@diagnostic disable: undefined-global +return { + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + config = function() + require("go").setup({ + lsp_cfg = false, + gofmt = false, + goimports = false, + linter = "golangci-lint", + test_runner = "go", + test_flags = { "-v" }, + dap_debug = true, + dap_debug_gui = true, + }) + end, + event = { "CmdlineEnter" }, + ft = { "go", "gomod" }, + build = ':lua require("go.install").update_all_sync()', +} diff --git a/lua/plugins/coding/zig.lua b/lua/plugins/coding/zig.lua new file mode 100644 index 00000000000..2690feda654 --- /dev/null +++ b/lua/plugins/coding/zig.lua @@ -0,0 +1,9 @@ +---@diagnostic disable: undefined-global +return { + "ziglang/zig.vim", + ft = "zig", + config = function() + -- Enable auto-formatting on save + vim.g.zig_fmt_autosave = 1 + end, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 00000000000..5dc5d2b8937 --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,18 @@ +---@diagnostic disable: undefined-global +return { -- You can easily change to a different colorscheme. + -- Change the name of the colorscheme plugin below, and then + -- change the command in the config to whatever the name of that colorscheme is. + -- + -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. + 'ellisonleao/gruvbox.nvim', + priority = 1000, -- Make sure to load this before all the other start plugins. + init = function() + -- Load the colorscheme here. + -- Like many other themes, this one has different styles, and you could load + -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. + vim.cmd.colorscheme 'gruvbox' + + -- You can configure highlights by doing something like: + vim.cmd.hi 'Comment gui=none' + end, +} diff --git a/lua/plugins/commentary.lua b/lua/plugins/commentary.lua new file mode 100644 index 00000000000..cf2c32c96d2 --- /dev/null +++ b/lua/plugins/commentary.lua @@ -0,0 +1,6 @@ +return { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end, +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 00000000000..a6b1caaf490 --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,47 @@ +---@diagnostic disable: undefined-global +return { -- Autoformat + 'stevearc/conform.nvim', + enabled = false, + event = { 'BufWritePre' }, + cmd = { 'ConformInfo' }, + keys = { + { + 'f', + function() + require('conform').format { async = true, lsp_format = 'fallback' } + end, + mode = '', + desc = '[F]ormat buffer', + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = {} -- C and C++ now enabled for format-on-save + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = 'never' + else + lsp_format_opt = 'fallback' + end + return { + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end, + formatters_by_ft = { + lua = { 'stylua' }, + go = { 'gofumpt', 'goimports' }, -- Run gofumpt first, then goimports + c = { 'clang_format' }, -- Add clang-format for C + cpp = { 'clang_format' }, -- Add clang-format for C++ + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use 'stop_after_first' to run the first available formatter from the list + -- javascript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, +} diff --git a/lua/plugins/dadbod.lua b/lua/plugins/dadbod.lua new file mode 100644 index 00000000000..6653504fe11 --- /dev/null +++ b/lua/plugins/dadbod.lua @@ -0,0 +1,68 @@ +---@diagnostic disable: undefined-global +-- Database explorer and query runner +return { + 'tpope/vim-dadbod', + dependencies = { + 'kristijanhusak/vim-dadbod-ui', -- UI for vim-dadbod + 'kristijanhusak/vim-dadbod-completion' -- Completion for SQL + }, + cmd = { + 'DBUI', + 'DBUIToggle', + 'DBUIAddConnection', + 'DBUIFindBuffer', + }, + init = function() + -- Save DBUI settings + vim.g.db_ui_save_location = vim.fn.stdpath("data") .. "/db_ui" + vim.g.db_ui_use_nerd_fonts = true + vim.g.db_ui_execute_on_save = false -- Don't auto-execute queries on save + vim.g.db_ui_table_helpers = { + -- Add useful SQL snippets + mysql = { + List = 'SELECT * FROM {table} LIMIT 100', + Indexes = 'SHOW INDEXES FROM {table}', + Foreign = 'SELECT * FROM information_schema.key_column_usage WHERE referenced_table_name = {table}', + }, + postgresql = { + List = 'SELECT * FROM {table} LIMIT 100', + Indexes = 'SELECT * FROM pg_indexes WHERE tablename = {table}', + Foreign = [[ + SELECT + tc.table_schema, + tc.constraint_name, + tc.table_name, + kcu.column_name, + ccu.table_schema AS foreign_table_schema, + ccu.table_name AS foreign_table_name, + ccu.column_name AS foreign_column_name + FROM + information_schema.table_constraints AS tc + JOIN information_schema.key_column_usage AS kcu + ON tc.constraint_name = kcu.constraint_name + AND tc.table_schema = kcu.table_schema + JOIN information_schema.constraint_column_usage AS ccu + ON ccu.constraint_name = tc.constraint_name + AND ccu.table_schema = tc.table_schema + WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name={table}; + ]], + }, + } + end, + config = function() + -- Enable SQL completion in SQL files and dadbod-ui buffers + vim.api.nvim_create_autocmd('FileType', { + pattern = {'sql', 'mysql', 'plsql', 'pgsql'}, + callback = function() + -- Set up completion + require('cmp').setup.buffer({ + sources = { + { name = 'vim-dadbod-completion' }, -- Database-aware completion + { name = 'nvim_lsp' }, -- LSP completion + { name = 'buffer' }, -- Buffer words + }, + }) + end, + }) + end, +} diff --git a/lua/plugins/garbage-day.lua b/lua/plugins/garbage-day.lua new file mode 100644 index 00000000000..cfdb687a6a7 --- /dev/null +++ b/lua/plugins/garbage-day.lua @@ -0,0 +1,21 @@ +-- Garbage collector that stops inactive LSP clients to free RAM +return { + --[[ 'zeioth/garbage-day.nvim', + dependencies = 'neovim/nvim-lspconfig', + event = 'VeryLazy', + opts = { + -- Collect garbage after 10 minutes of inactivity + grace_period = 60 * 10, + -- Exclude null-ls and other special clients + excluded_lsp_clients = { 'omnisharp', 'null-ls', 'none-ls' }, + -- Show notifications when clients are stopped + notifications = true, + -- Garbage collection settings + aggressive_mode = false, -- Be gentle with GC + -- Adjust Lua's GC parameters for better performance + gc_settings = { + pause = 110, -- Lower pause for more frequent but shorter GC pauses + step_mul = 100, -- Lower step multiplier for smoother collection + }, + }, ]] +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 00000000000..64f83e075f2 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,35 @@ +return { -- Adds git related signs to the gutter, as well as utilities for managing changes + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup({ + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = '~' }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + }) + end, +} diff --git a/lua/plugins/gitsigns/setup.lua b/lua/plugins/gitsigns/setup.lua new file mode 100644 index 00000000000..3c8716d6ca0 --- /dev/null +++ b/lua/plugins/gitsigns/setup.lua @@ -0,0 +1,28 @@ +---@diagnostic disable: undefined-global +-- GitSigns setup module +local M = {} + +function M.setup() + require('gitsigns').setup({ + signs = { + add = { text = '+' }, + change = { text = '~' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = '~' }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { interval = 1000, follow_files = true }, + attach_to_untracked = true, + current_line_blame = false, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, + preview_config = { border = 'single', style = 'minimal', relative = 'cursor', row = 0, col = 1 }, + }) +end + +return M diff --git a/lua/plugins/hover.lua b/lua/plugins/hover.lua new file mode 100644 index 00000000000..c8a187ce326 --- /dev/null +++ b/lua/plugins/hover.lua @@ -0,0 +1,44 @@ +---@diagnostic disable: undefined-global +return { + 'lewis6991/hover.nvim', + event = 'VeryLazy', + config = function() + require('hover').setup({ + init = function() + -- Required for hover.nvim + require('hover.providers.lsp') + -- Optional additional providers + require('hover.providers.gh') + require('hover.providers.man') + require('hover.providers.dictionary') + end, + preview_opts = { + border = 'rounded', + width = 80, + height = 20, + }, + title = true, + -- Key mappings + -- Use the same mapping as before ('K') + mappings = { + toggle_hover = 'K', + -- Scroll option + scroll_up = '', + scroll_down = '', + }, + }) + + -- Style adjustments + vim.api.nvim_set_hl(0, 'HoverFloat', { link = 'Normal' }) + vim.api.nvim_set_hl(0, 'HoverFloatBorder', { link = 'FloatBorder' }) + + -- Override the LSP hover handler to ensure our hover.nvim is used + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + -- Clear and override the K mapping to ensure it uses hover.nvim + vim.keymap.set('n', 'K', require('hover').hover, + { buffer = args.buf, desc = 'Enhanced documentation (hover.nvim)' }) + end, + }) + end, +} diff --git a/lua/plugins/illuminate.lua b/lua/plugins/illuminate.lua new file mode 100644 index 00000000000..bdef833f1b8 --- /dev/null +++ b/lua/plugins/illuminate.lua @@ -0,0 +1,35 @@ +---@diagnostic disable: undefined-global +return { + 'RRethy/vim-illuminate', + event = { "BufReadPost", "BufNewFile" }, + opts = { + delay = 200, + large_file_cutoff = 2000, + large_file_overrides = { + providers = { "lsp" } + }, + providers = { + 'lsp', + 'treesitter', + 'regex', + }, + min_count_to_highlight = 2, -- minimum number of matches required to perform highlighting + }, + config = function(_, opts) + require('illuminate').configure(opts) + + -- Set highlight style (using colors that match with gruvbox theme) + vim.api.nvim_set_hl(0, 'IlluminatedWordText', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordRead', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordWrite', { bg = '#3c3836', bold = true }) + + -- Map keys to navigate between highlighted words + vim.keymap.set('n', 'hn', function() + require('illuminate').goto_next_reference() + end, { desc = 'Go to next reference' }) + + vim.keymap.set('n', 'hp', function() + require('illuminate').goto_prev_reference() + end, { desc = 'Go to previous reference' }) + end, +} diff --git a/lua/plugins/indent-blankline.lua b/lua/plugins/indent-blankline.lua new file mode 100644 index 00000000000..c4dc25ab70b --- /dev/null +++ b/lua/plugins/indent-blankline.lua @@ -0,0 +1,8 @@ +-- Indentation guides for Neovim +return { + 'lukas-reineke/indent-blankline.nvim', + main = 'ibl', + event = { 'BufReadPre', 'BufNewFile' }, + opts = {}, -- Use ibl's defaults for best compatibility + +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 00000000000..49aa76a9c7f --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,13 @@ +---@diagnostic disable: undefined-global +local plugins = {} + +local plugin_files = vim.fn.globpath(vim.fn.stdpath('config') .. '/lua/plugins', '*.lua', false, true) + +for _, file in ipairs(plugin_files) do + local plugin_name = file:match('.*/(.*)%.lua$') + if plugin_name ~= 'init' then + table.insert(plugins, require('plugins.' .. plugin_name)) + end +end + +return plugins diff --git a/lua/plugins/lazydev.lua b/lua/plugins/lazydev.lua new file mode 100644 index 00000000000..6d9c256b2d6 --- /dev/null +++ b/lua/plugins/lazydev.lua @@ -0,0 +1,12 @@ +return { + -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + 'folke/lazydev.nvim', + ft = 'lua', + opts = { + library = { + -- Load luvit types when the `vim.uv` word is found + { path = 'luvit-meta/library', words = { 'vim%.uv' } }, + }, + }, +} diff --git a/lua/plugins/leap.lua b/lua/plugins/leap.lua new file mode 100644 index 00000000000..f61c9bf2185 --- /dev/null +++ b/lua/plugins/leap.lua @@ -0,0 +1,26 @@ +---@diagnostic disable: undefined-global +-- Quick navigation plugin +return { + url = "https://codeberg.org/andyg/leap.nvim", + dependencies = { + 'tpope/vim-repeat', -- For dot-repeat support + }, + config = function() + local leap = require('leap') + + -- Basic setup + leap.setup { + case_sensitive = false, + safe_labels = {}, -- Show all labels + labels = { + 'f', 'j', 'd', 'k', 's', 'l', 'h', 'g', + 'F', 'J', 'D', 'K', 'S', 'L', 'H', 'G', + }, + } + + -- Set highlight colors for better visibility + vim.api.nvim_set_hl(0, 'LeapMatch', { fg = '#89B4FA', bold = true, nocombine = true }) + vim.api.nvim_set_hl(0, 'LeapLabelPrimary', { fg = '#cfa369', bold = true, nocombine = true }) + vim.api.nvim_set_hl(0, 'LeapLabelSecondary', { fg = '#94E2D5', bold = true, nocombine = true }) + end, +} diff --git a/lua/plugins/lsp/overrides.lua b/lua/plugins/lsp/overrides.lua new file mode 100644 index 00000000000..9f7e5ad8a78 --- /dev/null +++ b/lua/plugins/lsp/overrides.lua @@ -0,0 +1,61 @@ +---@diagnostic disable: undefined-global +-- Override internal LSP functions to ensure position_encoding is always set + +local M = {} + +function M.setup() + -- Patch the symbols_to_items function to always use utf-16 encoding + -- and handle nil values safely + local original_symbols_to_items = vim.lsp.util.symbols_to_items + vim.lsp.util.symbols_to_items = function(symbols, bufnr, position_encoding) + -- Default to utf-16 if not specified + position_encoding = position_encoding or 'utf-16' + + -- Add extra safety checks for nil values + if not symbols or type(symbols) ~= 'table' then + return {} + end + + -- Call original with proper encoding + return original_symbols_to_items(symbols, bufnr, position_encoding) + end + + -- Patch workspace_symbol handler to be safer + vim.lsp.handlers['workspace/symbol'] = function(err, result, ctx, config) + if err or not result or vim.tbl_isempty(result) then + return {} + end + + -- Set a default position_encoding + local position_encoding = 'utf-16' + local client = vim.lsp.get_client_by_id(ctx.client_id) + if client and client.offset_encoding then + position_encoding = client.offset_encoding + end + + -- Process safely + local items = vim.lsp.util.symbols_to_items(result, nil, position_encoding) or {} + return items + end + + -- Patch all lsp_* functions in telescope.builtin to include position_encoding + local telescope_builtin = require('telescope.builtin') + local telescope_funcs = { + 'lsp_references', 'lsp_definitions', 'lsp_implementations', + 'lsp_type_definitions', 'lsp_document_symbols', 'lsp_workspace_symbols', + 'lsp_dynamic_workspace_symbols' + } + + for _, func_name in ipairs(telescope_funcs) do + local original_func = telescope_builtin[func_name] + telescope_builtin[func_name] = function(opts) + opts = opts or {} + if not opts.position_encoding then + opts.position_encoding = 'utf-16' + end + return original_func(opts) + end + end +end + +return M diff --git a/lua/plugins/lsp/servers.lua b/lua/plugins/lsp/servers.lua new file mode 100644 index 00000000000..d498272da6a --- /dev/null +++ b/lua/plugins/lsp/servers.lua @@ -0,0 +1,145 @@ +---@diagnostic disable: undefined-global +-- LSP servers configuration + +-- Go flags for build tags +local go_flags = 'integration' +local gopls_build_flags = go_flags ~= '' and { '-tags=' .. go_flags } or {} + +return { + -- Python + pyright = {}, + + -- Bash/Shell + bashls = { + filetypes = { 'sh', 'bash', 'zsh' }, + settings = { + bashIde = { + globPattern = '*@(.sh|.inc|.bash|.command)', + shellcheckPath = 'shellcheck', + }, + }, + }, + -- Go + gopls = { + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = false, + gofumpt = false, + hints = { + assignVariableTypes = false, + compositeLiteralFields = false, + compositeLiteralTypes = false, + constantValues = false, + functionTypeParameters = false, + parameterNames = false, + rangeVariableTypes = false, + }, + vulncheck = 'Off', + completionBudget = '100ms', + symbolMatcher = 'FastFuzzy', + symbolStyle = 'Dynamic', + diagnosticsDelay = '500ms', + buildFlags = gopls_build_flags, + }, + }, + }, + -- Lua + lua_ls = { + settings = { + Lua = { + runtime = { version = 'LuaJIT' }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + checkThirdParty = false, + library = { + [vim.fn.expand '$VIMRUNTIME/lua'] = true, + [vim.fn.stdpath 'config' .. '/lua'] = true, + }, + }, + telemetry = { enable = false }, + }, + }, + }, + -- C/C++ + clangd = { + cmd = { + 'clangd', + '--background-index', + '--clang-tidy', + '--header-insertion=iwyu', + '--completion-style=detailed', + '--function-arg-placeholders', + '--fallback-style=llvm', + }, + init_options = { + usePlaceholders = true, + completeUnimported = true, + clangdFileStatus = true, + }, + on_attach = function(client, bufnr) + -- Set the correct standard based on filetype + local filetype = vim.bo[bufnr].filetype + if filetype == 'c' then + client.config.init_options.fallbackFlags = { '-std=c23' } + elseif filetype == 'cpp' then + client.config.init_options.fallbackFlags = { '-std=c++23' } + end + + -- Call the default on_attach to setup keymaps and navic + require('plugins.lsp.setup').default_on_attach(client, bufnr) + end, + settings = { + clangd = { + InlayHints = { + Designators = true, + Enabled = true, + ParameterNames = true, + DeducedTypes = true, + }, + }, + }, + }, + + -- Zig + zls = { + settings = { + zls = { + -- Enable semantic highlighting + enable_semantic_tokens = true, + -- Enable inlay hints for better code understanding + enable_inlay_hints = true, + -- Enable snippets + enable_snippets = true, + -- Enable auto-fixing + enable_autofix = true, + -- Warn about style issues + warn_style = true, + -- Highlight global variables + highlight_global_var_declarations = true, + -- Enable build-on-save for faster feedback + enable_build_on_save = true, + -- Skip std library references for better performance + skip_std_references = false, + -- Prefer ast-check over zig fmt for faster response + prefer_ast_check_as_child_process = true, + -- Enable import embedfile argument completions + enable_import_embedfile_argument_completions = true, + }, + }, + }, + + -- SQL + sqls = { + settings = { + sqls = { + connections = {}, + lowercaseKeywords = true, + }, + }, + }, +} diff --git a/lua/plugins/lsp/setup.lua b/lua/plugins/lsp/setup.lua new file mode 100644 index 00000000000..40db6b09ad4 --- /dev/null +++ b/lua/plugins/lsp/setup.lua @@ -0,0 +1,162 @@ +---@diagnostic disable: undefined-global +-- LSP setup (mason + lspconfig) + +local M = {} + +function M.setup() + -- Apply LSP function overrides for position_encoding + require('plugins.lsp.overrides').setup() + + local servers = require('plugins.lsp.servers') + + -- Enhanced nvim-cmp capabilities (VSCode-like) + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem = { + documentationFormat = { 'markdown', 'plaintext' }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { valueSet = { 1 } }, + resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + }, + }, + } + -- Complete with all available methods and properties + capabilities.textDocument.completion.completionList = { + itemDefaults = { + 'commitCharacters', + 'editRange', + 'insertTextFormat', + 'insertTextMode', + 'data', + }, + } + -- Add semantic tokens for better syntax highlighting + capabilities.textDocument.semanticTokens = { + tokenTypes = { 'namespace', 'type', 'class', 'enum', 'interface', 'struct', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'event', 'function', 'method', 'macro', 'keyword', 'modifier', 'comment', 'string', 'number', 'regexp', 'operator', 'decorator' }, + tokenModifiers = { 'declaration', 'definition', 'readonly', 'static', 'deprecated', 'abstract', 'async', 'modification', 'documentation', 'defaultLibrary' }, + formats = { 'relative' }, + requests = { + range = true, + full = true, + }, + } + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + + -- Setup mason-lspconfig with handlers + local mason_lspconfig = require('mason-lspconfig') + mason_lspconfig.setup { + ensure_installed = vim.tbl_keys(servers), + handlers = { + function(server_name) + local config = servers[server_name] or {} + config.capabilities = capabilities + + -- Default on_attach to setup keymaps & navic + M.default_on_attach = function(client, bufnr) + require('core.keymaps').setup_lsp_keymaps(bufnr) + + -- Attach navic if client supports document symbols + if client.server_capabilities.documentSymbolProvider then + local status_ok, _ = pcall(require, 'nvim-navic') + if status_ok then + require('nvim-navic').attach(client, bufnr) + end + end + end + + -- Only set the default on_attach if one isn't already provided + if not config.on_attach then + config.on_attach = M.default_on_attach + end + + -- Enhance LSP capabilities for specific servers + if server_name == 'gopls' and config.on_attach then + local orig_on_attach = config.on_attach + config.on_attach = function(client, bufnr) + client.server_capabilities.semanticTokensProvider = nil + orig_on_attach(client, bufnr) + end + end + + -- Force all LSP servers to use incremental completions (like VSCode) + if not config.settings then config.settings = {} end + if not config.settings.completions then config.settings.completions = {} end + config.settings.completions.completeFunctionCalls = true + + -- Enhanced settings for Lua LSP + if server_name == 'lua_ls' then + if not config.settings.Lua then config.settings.Lua = {} end + config.settings.Lua.completion = { + callSnippet = "Replace", + showWord = "Disable", + workspaceWord = false, + displayContext = 5, + keywordSnippet = "Both", + postfix = ".", + } + -- More comprehensive inferencing + config.settings.Lua.hint = { + enable = true, + setType = true, + paramType = true, + paramName = "Literal", + arrayIndex = "Enable", + } + -- Better type resolution + config.settings.Lua.type = { + castNumberToInteger = true, + } + -- Add standard Lua libraries for better completion + if not config.settings.Lua.workspace then config.settings.Lua.workspace = {} end + if not config.settings.Lua.workspace.library then config.settings.Lua.workspace.library = {} end + + -- Include standard libraries + local lua_types = vim.fn.expand('~/.local/share/nvim/mason/packages/lua-language-server/libexec/meta/3rd') + if vim.fn.isdirectory(lua_types) == 1 then + config.settings.Lua.workspace.library[lua_types] = true + end + -- Enable all features + config.settings.Lua.hover = { enable = true, expandAlias = true } + config.settings.Lua.signatureHelp = { enable = true } + config.settings.Lua.diagnostics = { enable = true, globals = { "vim" } } + end + + require('lspconfig')[server_name].setup(config) + end, + }, + } + + -- Hover handler will now be provided by Blink + + -- Override references handler + vim.lsp.handlers['textDocument/references'] = function(err, result, ctx, config) + if not result or vim.tbl_isempty(result) then + vim.notify('No references found', vim.log.levels.INFO) + else + require('telescope.builtin').lsp_references() + end + end + + -- Override semanticTokens/full + vim.lsp.handlers['textDocument/semanticTokens/full'] = function(err, result, ctx, cfg) + if err or not result then return end + local client = vim.lsp.get_client_by_id(ctx.client_id) + if not client then return end + local bufnr = ctx.bufnr + local highlighter = vim.lsp.semantic_tokens.create_highlighter(bufnr, client) + if not highlighter then return end + pcall(function() + highlighter:process_response(result, client, ctx.request.version) + end) + end +end + +return M diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 00000000000..2d2c0447be7 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,73 @@ +---@diagnostic disable: undefined-global +return { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function() + require('lualine').setup { + options = { + theme = 'gruvbox', + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { + 'filename', + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + sections = { 'error', 'warn', 'info', 'hint' }, + symbols = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, + colored = true, + update_in_insert = false, + always_visible = true, + }, + { + function() + -- Get the navic location with a more reliable approach + local location = require('nvim-navic').get_location() + if location and location ~= "" then + return "📍 " .. location -- Add an icon for better visibility + end + return "" + end, + cond = function() + return package.loaded['nvim-navic'] and require('nvim-navic').is_available() + end, + color = { fg = '#a3be8c', gui = 'bold' }, -- Make it more visible with color + }, + }, + lualine_x = { + { + function() + local qf_list = vim.fn.getqflist() + local count = #qf_list + if count > 0 then + return 'QF:' .. count + else + return '' + end + end, + icon = '', + color = { fg = '#d7af5f', gui = 'bold' }, + }, + 'encoding', + 'fileformat', + 'filetype', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + extensions = { 'quickfix' }, + } + end, +} diff --git a/lua/plugins/lualine/setup.lua b/lua/plugins/lualine/setup.lua new file mode 100644 index 00000000000..5420300e7e8 --- /dev/null +++ b/lua/plugins/lualine/setup.lua @@ -0,0 +1,72 @@ +---@diagnostic disable: undefined-global +-- lualine setup module +local M = {} + +function M.setup() + require('lualine').setup { + options = { + theme = 'gruvbox', + section_separators = { left = '', right = '' }, + component_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { + 'filename', + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + sections = { 'error', 'warn', 'info', 'hint' }, + symbols = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' }, + colored = true, + update_in_insert = false, + always_visible = true, + }, + { + function() + local location = require('nvim-navic').get_location() + if location and location ~= '' then + return '📍 ' .. location + end + return '' + end, + cond = function() + return package.loaded['nvim-navic'] and require('nvim-navic').is_available() + end, + color = { fg = '#a3be8c', gui = 'bold' }, + }, + }, + lualine_x = { + { + function() + local qf_list = vim.fn.getqflist() + local count = #qf_list + if count > 0 then + return 'QF:' .. count + end + return '' + end, + icon = '', + color = { fg = '#d7af5f', gui = 'bold' }, + }, + 'encoding', + 'fileformat', + 'filetype', + }, + lualine_y = { 'progress' }, + lualine_z = { 'location' }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {}, + }, + extensions = { 'quickfix' }, + } +end + +return M diff --git a/lua/plugins/luvit-meta.lua b/lua/plugins/luvit-meta.lua new file mode 100644 index 00000000000..da6ddc7315c --- /dev/null +++ b/lua/plugins/luvit-meta.lua @@ -0,0 +1 @@ +return { 'Bilal2453/luvit-meta', lazy = true } diff --git a/lua/plugins/mason-null-ls.lua b/lua/plugins/mason-null-ls.lua new file mode 100644 index 00000000000..a94e7253d3f --- /dev/null +++ b/lua/plugins/mason-null-ls.lua @@ -0,0 +1,18 @@ +return { + "jay-babu/mason-null-ls.nvim", + enabled = true, + dependencies = { + "williamboman/mason.nvim", + "nvimtools/none-ls.nvim", -- replaces null-ls + }, + config = function() + require("mason-null-ls").setup({ + ensure_installed = + { + "prettier", + "eslint" + }, + automatic_installation = true, + }) + end, +} diff --git a/lua/plugins/mini-icons.lua b/lua/plugins/mini-icons.lua new file mode 100644 index 00000000000..b6a0bdbe601 --- /dev/null +++ b/lua/plugins/mini-icons.lua @@ -0,0 +1,42 @@ +return { + 'echasnovski/mini.nvim', + version = false, + config = function() + require('mini.icons').setup({ + -- Enable all preset kinds + preset = 'default', + -- Customize icons for specific kinds + devicons = { + enabled = true, + override = { + -- File types + default = '', + lua = '', + python = '', + javascript = '', + html = '', + css = '', + json = '', + yaml = '', + toml = '', + markdown = '', + -- Git + git = '', + github = '', + gitlab = '', + gitignore = '', + -- Folders + folder = '', + folder_open = '', + folder_empty = '', + folder_empty_open = '', + -- LSP + error = '', + warning = '', + info = '', + hint = '󰌵', + }, + }, + }) + end, +} diff --git a/lua/plugins/mini-surround.lua b/lua/plugins/mini-surround.lua new file mode 100644 index 00000000000..26ea8741ca6 --- /dev/null +++ b/lua/plugins/mini-surround.lua @@ -0,0 +1,11 @@ +return { + 'echasnovski/mini.surround', + version = '*', + event = 'VeryLazy', + config = function() + require('mini.surround').setup({ + -- Use mappings from centralized keymaps + mappings = require('core.keymaps').mini_surround_keymaps + }) + end, +} diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua new file mode 100644 index 00000000000..d1e64f41472 --- /dev/null +++ b/lua/plugins/null-ls.lua @@ -0,0 +1,43 @@ +---@diagnostic disable: undefined-global +local vim = vim + +local M = { + 'nvimtools/none-ls.nvim', + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { + 'jay-babu/mason-null-ls.nvim', + }, + config = function() + -- Safely require null-ls + local ok, null_ls = pcall(require, 'null-ls') + if not ok then + vim.notify('Failed to load null-ls', vim.log.levels.ERROR) + return + end + + -- Safely require setup + local setup_ok, setup = pcall(require, 'plugins.null-ls.setup') + if not setup_ok or type(setup.setup) ~= 'function' then + vim.notify('Failed to load null-ls setup', vim.log.levels.ERROR) + return + end + + -- Initialize null-ls + setup.setup() + + -- Additional safety check for sources + vim.defer_fn(function() + if not null_ls or not null_ls.get_sources then + vim.notify('null-ls sources not available', vim.log.levels.WARN) + return + end + + local sources = null_ls.get_sources() + if #sources == 0 then + vim.notify('No null-ls sources registered', vim.log.levels.WARN) + end + end, 1000) -- Check after 1 second + end, +} + +return M diff --git a/lua/plugins/null-ls/setup.lua b/lua/plugins/null-ls/setup.lua new file mode 100644 index 00000000000..fcc220ab222 --- /dev/null +++ b/lua/plugins/null-ls/setup.lua @@ -0,0 +1,53 @@ +---@diagnostic disable: undefined-global +-- null-ls setup module +local M = {} + +function M.setup() + local null_ls = require 'null-ls' + local null_ls_utils = require 'null-ls.utils' + local formatting = null_ls.builtins.formatting + local diagnostics = null_ls.builtins.diagnostics + + local sources = { + formatting.gofumpt.with({ extra_args = { "-extra" } }), + formatting.goimports.with({ args = { "-local", "", "-w", "$FILENAME" } }), + diagnostics.golangci_lint.with({ + diagnostics_format = '#{m}', + extra_args = { + '--fast', + '--max-issues-per-linter', '30', + '--max-same-issues', '4', + '--max-same-issues-per-linter', '0', + '--fix=false', + '--tests=false', + '--print-issued-lines=false', + '--timeout=10s', + '--out-format=json', + }, + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + timeout = 10000, + }), + formatting.prettier.with { + filetypes = { 'css', 'scss', 'html', 'markdown', 'yaml', 'yml' }, + extra_args = { + '--bracket-same-line', + '--trailing-comma', 'all', + '--tab-width', '2', + '--semi', + '--single-quote', + }, + }, + formatting.shfmt.with { extra_args = { '-i', '2', '-ci', '-bn' } }, + formatting.sqlfluff.with { extra_args = { '--dialect', 'tsql' } }, + } + + null_ls.setup { + root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git'), + timeout = 10000, + debounce = 250, + update_in_insert = false, + sources = sources, + } +end + +return M diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua new file mode 100644 index 00000000000..dd9fdbb8e98 --- /dev/null +++ b/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,8 @@ +return { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + opts = nil, + config = function() + require('plugins.nvim-autopairs.setup').setup(require('plugins.nvim-autopairs.setup').opts) + end, +} diff --git a/lua/plugins/nvim-autopairs/setup.lua b/lua/plugins/nvim-autopairs/setup.lua new file mode 100644 index 00000000000..f4ed31f51b4 --- /dev/null +++ b/lua/plugins/nvim-autopairs/setup.lua @@ -0,0 +1,36 @@ +---@diagnostic disable: undefined-global +-- nvim-autopairs setup module +local M = {} + +M.opts = { + check_ts = true, + ts_config = { + lua = { "string" }, + javascript = { "template_string" }, + java = false, + }, + ignored_next_char = "[%w%.]", + enable_moveright = false, + enable_afterquote = false, + enable_check_bracket_line = true, + enable_bracket_in_quote = false, + map_cr = true, + map_bs = true, + map_c_h = false, + map_c_w = false, + disable_in_macro = true, + disable_in_visualblock = true, + enable_abbr = false, +} + +function M.setup(opts) + local npairs = require('nvim-autopairs') + npairs.setup(opts) + local ok, cmp = pcall(require, 'cmp') + if ok then + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done()) + end +end + +return M diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 00000000000..25054fd678f --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,41 @@ +---@diagnostic disable: undefined-global +return { -- Autocompletion + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + 'L3MON4D3/LuaSnip', + build = (function() + -- Build Step is needed for regex support in snippets. + -- This step is not supported in many windows environments. + -- Remove the below condition to re-enable on windows. + if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then + return + end + return 'make install_jsregexp' + end)(), + dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. + -- See the README about individual language/framework/plugin snippets: + -- https://github.com/rafamadriz/friendly-snippets + { + 'rafamadriz/friendly-snippets', + config = function() + require('luasnip.loaders.from_vscode').lazy_load() + end, + }, + }, + }, + 'saadparwaiz1/cmp_luasnip', + + -- Adds other completion capabilities. + -- nvim-cmp does not ship with all sources by default. They are split + -- into multiple repos for maintenance purposes. + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-path', + }, + config = function() + require('plugins.cmp.setup').setup() + end, +} diff --git a/lua/plugins/nvim-lspconfig.lua b/lua/plugins/nvim-lspconfig.lua new file mode 100644 index 00000000000..8926b656f27 --- /dev/null +++ b/lua/plugins/nvim-lspconfig.lua @@ -0,0 +1,98 @@ +---@diagnostic disable: undefined-global +local go_flags = 'integration' -- add the tags here, instead of searching it below + +return { + -- Main LSP Configuration + 'neovim/nvim-lspconfig', + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + -- Automatically install LSPs and related tools to stdpath for Neovim + { + 'williamboman/mason.nvim', + cmd = { "Mason", "MasonInstall", "MasonUpdate" }, + config = function() + require("mason").setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + }, + border = "rounded", + width = 0.8, + height = 0.9, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, + }) + end + }, + { + 'williamboman/mason-lspconfig.nvim', + dependencies = { 'williamboman/mason.nvim' }, + config = function() + require("mason-lspconfig").setup({ + automatic_installation = true + }) + end + }, + -- 'folke/neodev.nvim', -- Adds support for Neovim Lua API -- No longer needed with lazydev + { + 'WhoIsSethDaniel/mason-tool-installer.nvim', + event = 'VeryLazy', + config = function() + require('mason-tool-installer').setup { + ensure_installed = { + 'lua-language-server', + 'stylua', -- Lua formatter + 'marksman', + -- Go tools + 'gopls', -- Go LSP + 'gofumpt', -- Stricter Go formatter + 'goimports', -- Go import manager + 'golangci-lint', -- Go linter + 'delve', -- Go debugger + -- Zig tools + 'zls', -- Zig LSP + -- C tools + 'clangd', -- C/C++ LSP + 'clang-format', -- C/C++ formatter + 'codelldb', -- Native code debugger + -- Python tools + 'pyright', -- Python LSP + 'black', -- Python formatter + 'ruff', -- Python linter + 'debugpy', -- Python debugger + -- SQL tools + 'sqls', -- Advanced SQL LSP + -- Shell tools + 'bash-language-server', -- Bash LSP + 'shellcheck', -- Shell linter + 'shfmt', -- Shell formatter + }, + auto_update = true, + run_on_start = true, + } + end, + }, + + -- Useful status updates for LSP. + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { 'j-hui/fidget.nvim', opts = {} }, + + -- Allows extra capabilities provided by nvim-cmp + 'hrsh7th/cmp-nvim-lsp', + + -- Add nvim-navic for breadcrumbs + { 'SmiteshP/nvim-navic', config = function() + require('nvim-navic').setup { + highlight = true, + separator = ' > ', + depth_limit = 5, + } + end }, + }, + config = function() + require('plugins.lsp.setup').setup() + end, +} diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua new file mode 100644 index 00000000000..0e7f0b0a349 --- /dev/null +++ b/lua/plugins/nvim-treesitter.lua @@ -0,0 +1,53 @@ +return { + { + 'nvim-treesitter/nvim-treesitter', + branch = 'main', + lazy = false, + build = ':TSUpdate', + config = function() + local parsers = { + 'bash', 'c', 'cpp', 'diff', 'html', 'lua', 'luadoc', + 'markdown', 'markdown_inline', 'python', 'rust', + 'javascript', 'typescript', 'tsx', 'json', 'yaml', 'query', + 'vim', 'vimdoc', 'comment', 'regex', 'go', 'gomod', 'gosum', + } + + local nts = require('nvim-treesitter') + local installed = nts.get_installed and nts.get_installed('parsers') or {} + local have = {} + for _, p in ipairs(installed) do have[p] = true end + local missing = {} + for _, p in ipairs(parsers) do + if not have[p] then table.insert(missing, p) end + end + if #missing > 0 then nts.install(missing) end + + local max_filesize = 100 * 1024 + vim.api.nvim_create_autocmd('FileType', { + callback = function(args) + local buf = args.buf + local lang = vim.treesitter.language.get_lang(vim.bo[buf].filetype) + if not lang then return end + local ok_p = pcall(vim.treesitter.language.add, lang) + if not ok_p then return end + + local fname = vim.api.nvim_buf_get_name(buf) + local ok, stats = pcall(vim.loop.fs_stat, fname) + if ok and stats and stats.size > max_filesize then return end + + pcall(vim.treesitter.start, buf, lang) + + if lang ~= 'yaml' then + vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, + }) + end, + }, + { + 'nvim-treesitter/nvim-treesitter-textobjects', + branch = 'main', + dependencies = { 'nvim-treesitter/nvim-treesitter' }, + event = 'VeryLazy', + }, +} diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua new file mode 100644 index 00000000000..5ec46cf9c06 --- /dev/null +++ b/lua/plugins/session.lua @@ -0,0 +1,52 @@ +---@diagnostic disable: undefined-global +return { + 'echasnovski/mini.sessions', + version = '*', + event = 'VimEnter', + config = function() + local function get_session_name() + return vim.fn.fnamemodify(vim.fn.getcwd(), ':t') + end + + -- Cache Go project check per directory + local go_project_cache = {} + local function is_go_project() + local cwd = vim.fn.getcwd() + if go_project_cache[cwd] == nil then + -- Single glob with brace expansion + go_project_cache[cwd] = vim.fn.glob(cwd .. '/{*.go,go.mod,go.work}') ~= '' + end + return go_project_cache[cwd] + end + + require('mini.sessions').setup({ + autoread = false, + autowrite = true, + directory = vim.fn.stdpath('data') .. '/sessions', + file = '', + force = { read = false, write = true, delete = false }, + hooks = { + pre = { + read = function() return not is_go_project() end, + write = function() return not is_go_project() end, + }, + -- After successful action + post = { read = nil, write = nil, delete = nil }, + }, + -- Whether to print session path after action + verbose = { read = false, write = true, delete = true }, + }) + + -- Set up autocommands for auto-saving + local session_group = vim.api.nvim_create_augroup('mini_sessions', { clear = true }) + vim.api.nvim_create_autocmd('VimLeavePre', { + group = session_group, + callback = function() + local name = get_session_name() + if name then + require('mini.sessions').write(name, { force = true }) + end + end, + }) + end, +} diff --git a/lua/plugins/snacks.lua b/lua/plugins/snacks.lua new file mode 100644 index 00000000000..91991713609 --- /dev/null +++ b/lua/plugins/snacks.lua @@ -0,0 +1,3 @@ +-- This is the main entry point for snacks configuration +-- All actual configurations are in the snacks/ directory +return require("plugins.snacks.init") diff --git a/lua/plugins/snacks/core.lua b/lua/plugins/snacks/core.lua new file mode 100644 index 00000000000..5ba8516e87b --- /dev/null +++ b/lua/plugins/snacks/core.lua @@ -0,0 +1,34 @@ +return { + bigfile = { enabled = true }, + input = { enabled = true }, + notifier = { + enabled = true, + timeout = 3000, -- notifications auto-close after 3s + render = { + max_width = 100, + min_width = 20, + padding = 1, + format = { + default = " {message}", + notify = " {title}\n {message}", + error = " {title}\n {message}", + warn = " {title}\n {message}", + info = " {title}\n {message}", + }, + }, + }, + quickfile = { enabled = true }, + statuscolumn = { enabled = true }, + scratch = { + enabled = true, + float = { + border = "rounded", + width = 0.8, + height = 0.8, + }, + }, + bufdelete = { + enabled = true, + next = "cycle", + }, +} diff --git a/lua/plugins/snacks/dashboard.lua b/lua/plugins/snacks/dashboard.lua new file mode 100644 index 00000000000..0f328349bff --- /dev/null +++ b/lua/plugins/snacks/dashboard.lua @@ -0,0 +1,19 @@ +return { + dashboard = { + enabled = true, + preset = { + header = [[ + ███▄ █ ▓█████ ▒█████ ██▒ █▓ ██▓ ███▄ ▄███▓ + ██ ▀█ █ ▓█ ▀ ▒██▒ ██▒▓██░ █▒▓██▒▓██▒▀█▀ ██▒ +▓██ ▀█ ██▒▒███ ▒██░ ██▒ ▓██ █▒░▒██▒▓██ ▓██░ +▓██▒ ▐▌██▒▒▓█ ▄ ▒██ ██░ ▒██ █░░░██░▒██ ▒██ +▒██░ ▓██░░▒████▒░ ████▓▒░ ▒▀█░ ░██░▒██▒ ░██▒ +░ ▒░ ▒ ▒ ░░ ▒░ ░░ ▒░▒░▒░ ░ ▐░ ░▓ ░ ▒░ ░ ░ +░ ░░ ░ ▒░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ▒ ░░ ░ ░ + ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ▒ ░░ ░ + ░ ░ ░ ░ ░ ░ ░ ░ + ░ +]], + }, + }, +} diff --git a/lua/plugins/snacks/display.lua b/lua/plugins/snacks/display.lua new file mode 100644 index 00000000000..b2b09560415 --- /dev/null +++ b/lua/plugins/snacks/display.lua @@ -0,0 +1,15 @@ +return { + display = { + enabled = true, + indent = { enabled = true }, + references = { enabled = true }, + scope = { enabled = true }, + dim = { enabled = true }, + }, + notifier = { + enabled = true, + timeout = 5000, + max_width = 100, + max_height = 10, + }, +} diff --git a/lua/plugins/snacks/git.lua b/lua/plugins/snacks/git.lua new file mode 100644 index 00000000000..61d01a6f398 --- /dev/null +++ b/lua/plugins/snacks/git.lua @@ -0,0 +1,16 @@ +return { + git = { enabled = true }, + gitbrowse = { + enabled = true, + notify = true, + what = "commit", + }, + lazygit = { + enabled = true, + float = { + border = "rounded", + width = 0.9, + height = 0.9, + }, + }, +} diff --git a/lua/plugins/snacks/init.lua b/lua/plugins/snacks/init.lua new file mode 100644 index 00000000000..10bd67c52b4 --- /dev/null +++ b/lua/plugins/snacks/init.lua @@ -0,0 +1,49 @@ +---@diagnostic disable: undefined-global +-- Import all configurations +local core = require("plugins.snacks.core") +local display = require("plugins.snacks.display") +local git = require("plugins.snacks.git") +local terminal = require("plugins.snacks.terminal") +local dashboard = require("plugins.snacks.dashboard") +local picker = require("plugins.snacks.picker") + +-- Merge all configurations +local function merge_tables(...) + local result = {} + for _, t in ipairs({...}) do + for k, v in pairs(t) do + result[k] = v + end + end + return result +end + +-- Return the plugin spec +return { + 'folke/snacks.nvim', + priority = 1000, + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", -- optional, for file icons + "MunifTanjim/nui.nvim", + "echasnovski/mini.nvim", + }, + opts = merge_tables( + core, + display, + git, + terminal, + dashboard, + picker + ), + config = function(_, opts) + -- Initialize snacks with merged options + require("snacks").setup(opts) + + -- Note: Keymaps are handled in core/keymaps.lua + end, + init = function() + -- Make snacks available globally for debugging + _G.Snacks = require("plugins.snacks.init") + end, +} diff --git a/lua/plugins/snacks/picker.lua b/lua/plugins/snacks/picker.lua new file mode 100644 index 00000000000..e8bf2477664 --- /dev/null +++ b/lua/plugins/snacks/picker.lua @@ -0,0 +1,27 @@ +return { + picker = { + sources = { + explorer = { + tree = true, + watch = true, + diagnostics = true, + diagnostics_open = false, + git_status = true, + git_status_open = false, + git_untracked = true, + follow_file = true, + focus = "list", + auto_close = false, + jump = { close = false }, + formatters = { + file = { filename_only = true }, + severity = { pos = "right" }, + }, + matcher = { sort_empty = false, fuzzy = false }, + -- Add safety options + safe_update = true, -- Skip updates if buffer is being written/closed + ignore_nil_buffers = true, -- Skip nil buffers during updates + } + } + }, +} diff --git a/lua/plugins/snacks/terminal.lua b/lua/plugins/snacks/terminal.lua new file mode 100644 index 00000000000..b9220453a02 --- /dev/null +++ b/lua/plugins/snacks/terminal.lua @@ -0,0 +1,14 @@ +return { + terminal = { + enabled = true, + float = { + border = "rounded", + width = 0.8, + height = 0.8, + }, + -- Set to true for better toggle behavior + persistent = true, + -- Auto-close terminal when process exits + auto_close = true, + }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 00000000000..4ced8ca1f00 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,29 @@ +---@diagnostic disable: undefined-global +return { -- Fuzzy Finder (files, lsp, etc) + 'nvim-telescope/telescope.nvim', + event = 'VimEnter', + branch = '0.1.x', + dependencies = { + 'nvim-lua/plenary.nvim', + { -- If encountering errors, see telescope-fzf-native README for installation instructions + 'nvim-telescope/telescope-fzf-native.nvim', + + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', + + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable 'make' == 1 + end, + }, + { 'nvim-telescope/telescope-ui-select.nvim' }, + + -- Useful for getting pretty icons, but requires a Nerd Font. + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + }, + config = function() + require('plugins.telescope.setup').setup() + end, +} diff --git a/lua/plugins/telescope/setup.lua b/lua/plugins/telescope/setup.lua new file mode 100644 index 00000000000..6f3dca2eef3 --- /dev/null +++ b/lua/plugins/telescope/setup.lua @@ -0,0 +1,45 @@ +---@diagnostic disable: undefined-global +local M = {} + +function M.setup() + -- Base Telescope configuration + require('telescope').setup { + defaults = { + mappings = { + i = { [''] = 'which_key' }, + n = { ['?'] = 'which_key' }, + }, + }, + extensions = { + ['ui-select'] = { require('telescope.themes').get_dropdown() }, + }, + } + + -- Load extensions + pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') + + -- Apply keymaps from core.keymaps + local keymaps = require('core.keymaps').telescope_keymaps + for _, mapping in ipairs(keymaps) do + vim.keymap.set(mapping.mode, mapping.lhs, mapping.rhs, mapping.opts) + end + + -- Additional builtins mapping (if not handled by core) + local builtin = require 'telescope.builtin' + vim.keymap.set('n', 'gr', builtin.lsp_references, { desc = 'LSP: [G]oto [R]eferences' }) + vim.keymap.set('n', 'gd', builtin.lsp_definitions, { desc = 'LSP: [G]oto [D]efinition' }) + vim.keymap.set('n', 'gI', builtin.lsp_implementations, { desc = 'LSP: [G]oto [I]mplementation' }) + -- Other mappings moved from inline config + vim.keymap.set('n', '/', function() + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { winblend = 10, previewer = false }) + end, { desc = '[/] Fuzzily search in current buffer' }) + vim.keymap.set('n', 's/', function() + builtin.live_grep { grep_open_files = true, prompt_title = 'Live Grep in Open Files' } + end, { desc = '[S]earch [/] in Open Files' }) + vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } + end, { desc = '[S]earch [N]eovim files' }) +end + +return M diff --git a/lua/plugins/todo-comments.lua b/lua/plugins/todo-comments.lua new file mode 100644 index 00000000000..c11461df8e1 --- /dev/null +++ b/lua/plugins/todo-comments.lua @@ -0,0 +1,9 @@ +return { + 'folke/todo-comments.nvim', + event = 'VimEnter', + dependencies = { 'nvim-lua/plenary.nvim' }, + opts = { + signs = false, + -- Keymaps are handled in core/keymaps.lua + } +} diff --git a/lua/plugins/vim-sleuth.lua b/lua/plugins/vim-sleuth.lua new file mode 100644 index 00000000000..ad6149e845a --- /dev/null +++ b/lua/plugins/vim-sleuth.lua @@ -0,0 +1 @@ +return { 'tpope/vim-sleuth' } diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 00000000000..5080897ea64 --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,112 @@ +---@diagnostic disable: undefined-global +return { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + opts = { + delay = 0, + icons = { + mappings = vim.g.have_nerd_font, + 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 = { + { 'c', group = '[C]ode', desc = { + a = 'Code [A]ction', + f = '[F]ormat buffer', + }}, + { 'd', group = '[D]ocument', desc = { + x = 'Document [D]iagnostics', + s = 'Document [S]ymbols', + [''] = 'Show diagnostic under cursor', + }}, + { 's', group = '[S]earch', desc = { + h = '[H]elp', + k = '[K]eymaps', + f = '[F]iles', + s = '[S]elect Telescope', + w = 'Current [W]ord', + g = '[G]rep', + d = '[D]iagnostics', + r = '[R]esume last search', + ['/'] = 'Search in open files', + n = '[N]eovim config files', + }}, + { 'l', group = '[L]SP/Language' }, + { 'm', group = '[M]emory/Sessions' }, + { 'D', group = '[D]atabase' }, + { 't', group = '[T]roubleshooting', desc = { + d = 'Search all [D]iagnostics', + l = 'Diagnostics in [L]ocation list', + t = 'Diagnostic details in floa[T]', + }}, + { 'w', desc = 'Save file' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'g', group = '[G]it', desc = { + s = 'Status', + }}, + { 'f', group = '[F]ile Explorer', desc = { + e = 'Toggle explorer', + f = 'Focus explorer', + }}, + { 'n', group = '[N]otifications', desc = { + n = 'Toggle notifications', + h = 'Notification [H]istory', + c = '[C]lear notifications', + }}, + { 'p', group = 'Debug/[P]rofile', desc = { + b = 'Toggle [B]reakpoint', + c = '[C]ontinue debugging', + n = 'Step over ([N]ext)', + i = 'Step [I]nto', + o = 'Step [O]ut', + r = 'Open [R]EPL', + l = 'Run [L]ast debug session', + x = 'Toggle debug UI', + }}, + { 'b', group = '[B]uffer', desc = { + p = '[P]revious', + n = '[N]ext', + d = '[D]elete', + D = 'Force [D]elete', + }}, + { 'q', desc = 'Open diagnostic [Q]uickfix list' }, + { 'e', desc = 'Toggle file [E]xplorer' }, + { 'o', desc = 'F[o]cus file explorer' }, + { 'x', desc = 'Close buffer' }, + { 'X', desc = 'Force close buffer' }, + { '/', desc = 'Search in current buffer' }, + { '', desc = 'Find buffers' }, + { '', desc = 'Search text in all files' }, + }, + }, +} diff --git a/lua/plugins/work/gopls_flags.txt b/lua/plugins/work/gopls_flags.txt new file mode 100644 index 00000000000..1cff4fb4a74 --- /dev/null +++ b/lua/plugins/work/gopls_flags.txt @@ -0,0 +1 @@ +-tags=integration