diff --git a/IMPROVEMENTS.md b/IMPROVEMENTS.md new file mode 100644 index 0000000..4f85d69 --- /dev/null +++ b/IMPROVEMENTS.md @@ -0,0 +1,644 @@ +# Neovim Configuration Improvements & Recommendations + +**Generated:** 2024 +**Status:** Analysis Complete + +--- + +## ๐Ÿ“‹ Table of Contents + +1. [Critical Issues](#critical-issues) +2. [Keymap Conflicts & Duplicates](#keymap-conflicts--duplicates) +3. [Code Quality & Organization](#code-quality--organization) +4. [Performance Optimizations](#performance-optimizations) +5. [Missing Features & Enhancements](#missing-features--enhancements) +6. [Documentation Updates](#documentation-updates) +7. [Plugin Management](#plugin-management) +8. [Security & Best Practices](#security--best-practices) +9. [Quick Wins](#quick-wins) + +--- + +## ๐Ÿ”ด Critical Issues + +### 1. โœ… **Duplicate Copilot Panel Keymaps** (FIXED) +**Location:** `lua/cargdev/core/keymaps/personal.lua` and `lua/cargdev/core/keymaps/copilot.lua` + +**Issue:** `cp` was mapped in both files. Also had conflict with `ce` (enable vs explain). + +**Resolution:** +- Removed duplicate `cp` from `personal.lua` +- Removed conflicting `ce` from `personal.lua` (Copilot enable in `copilot.lua` takes precedence) +- All Copilot panel keymaps now centralized in `copilot.lua` + +**Priority:** ๐Ÿ”ด High โœ… Fixed + +--- + +### 2. **Duplicate Window Management Keymaps** +**Location:** `lua/cargdev/core/keymaps/personal.lua` and `lua/cargdev/core/keymaps/window.lua` + +**Issue:** Window split keymaps (`sv`, `sh`, etc.) are duplicated. + +**Impact:** Redundant code, maintenance burden. + +**Recommendation:** +```lua +-- Consolidate all window management in window.lua +-- Remove duplicates from personal.lua +``` + +**Priority:** ๐ŸŸก Medium + +--- + +## โš ๏ธ Keymap Conflicts & Duplicates + +### 4. **Session Management Keymap Conflict** +**Location:** `lua/cargdev/core/keymaps/plugins.lua` (lines 46-47) and `lua/cargdev/core/keymaps/personal.lua` (line 22) + +**Issue:** +- `plugins.lua`: `ss` = SessionSave +- `personal.lua`: `so` = Reload nvim (source %) + +**Note:** These don't conflict directly, but `ss` conflicts with Substitute line in `plugins.lua` line 54. + +**Recommendation:** +```lua +-- Rename session save/restore to avoid confusion: +-- sS = SessionSave +-- sR = SessionRestore +-- Or use a dedicated prefix: se (session) +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 5. **Substitute Keymap Already Conflicts** +**Location:** `lua/cargdev/core/keymaps/plugins.lua` line 54 + +**Issue:** `ss` is used for both SessionSave and Substitute line. + +**Current State:** Comment says "changed from s to sub to avoid conflicts" but `ss` still conflicts. + +**Recommendation:** +```lua +-- Use subs for substitute line +-- Keep ss for session save +-- Or use sS for session save +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 6. **Tab Keymap Conflicts** +**Location:** Multiple files handle Tab key + +**Issue:** Tab is handled by: +- Copilot keymaps (`copilot.lua`) +- nvim-cmp (`nvim-cmp.lua`) +- Both coordinate, but could be cleaner + +**Current State:** โœ… Working correctly with coordination, but could be documented better. + +**Recommendation:** +- Add comments explaining the coordination +- Consider using a unified handler function + +**Priority:** ๐ŸŸข Low (working, but could be cleaner) + +--- + +## ๐Ÿงน Code Quality & Organization + +### 7. **Temporary/Unused Files** +**Location:** Root directory + +**Files Found:** +- `kkk` - Unknown purpose, appears to be temporary +- `cleanup_deprecated_adapters.lua` - Cleanup script that may not be needed anymore + +**Recommendation:** +```bash +# Review and remove if not needed: +- kkk +- cleanup_deprecated_adapters.lua (if cleanup already done) +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 8. **Commented Code Should Be Removed** +**Location:** Multiple files + +**Examples:** +- `lua/cargdev/core/keymaps/personal.lua` lines 66-69 (commented Tmux navigation) +- `lua/cargdev/core/keymaps/general.lua` line 12 (commented x keymap) +- `lua/cargdev/core/init.lua` lines 58-64 (commented project_config bootstrap) + +**Recommendation:** +```lua +-- Remove commented code or convert to proper documentation +-- Use git history if you need to reference old code +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 9. **Inconsistent Keymap Description Format** +**Location:** Various keymap files + +**Issue:** Some descriptions are verbose, some are brief. No consistent style. + +**Examples:** +- `{ desc = "Toggle comment" }` vs `{ desc = "Copilot: Accept suggestion" }` +- Some use prefixes (Copilot:, Git:), some don't + +**Recommendation:** +```lua +-- Standardize description format: +-- For plugin-specific: "PluginName: Action" +-- For general: "Action" +-- Example: { desc = "Copilot: Accept suggestion" } +-- Example: { desc = "Toggle comment" } +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 10. **Unused Variables in general.lua** +**Location:** `lua/cargdev/core/keymaps/general.lua` line 19 + +**Issue:** `vault_path` is defined but only used if Obsidian link function is called. + +**Recommendation:** +```lua +-- Move vault_path inside the function or add a check: +local vault_path = vim.env.IDEA_DIR +if not vault_path then + vim.notify("IDEA_DIR environment variable not set", vim.log.levels.WARN) + return +end +``` + +**Priority:** ๐ŸŸข Low + +--- + +## โšก Performance Optimizations + +### 11. **Redundant Filetype Detection** +**Location:** `lua/cargdev/core/init.lua` lines 37-42 + +**Issue:** Force filetype detection on every BufRead might be redundant. + +**Current Code:** +```lua +vim.api.nvim_create_autocmd("BufRead", { + pattern = "*", + callback = function() + vim.cmd("silent filetype detect") + end, +}) +``` + +**Recommendation:** +```lua +-- Only run if filetype is not already detected: +vim.api.nvim_create_autocmd("BufRead", { + pattern = "*", + callback = function() + if vim.bo.filetype == "" then + vim.cmd("silent filetype detect") + end + end, +}) +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 12. **Double Function Loading** +**Location:** `lua/cargdev/core/init.lua` lines 44-56 + +**Issue:** Functions are loaded twice - once immediately and once on VimEnter. + +**Recommendation:** +```lua +-- Remove the immediate load, keep only VimEnter +-- Or add a flag to prevent double-loading +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 13. **Syntax Highlighting Column Limit Set Twice** +**Location:** `lua/cargdev/core/options.lua` lines 43 and 52 + +**Issue:** `synmaxcol` is set to 240 and then 200. + +**Recommendation:** +```lua +-- Remove duplicate, keep only one value (200 is more conservative) +opt.synmaxcol = 200 +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 14. **Foldmethod Set Twice** +**Location:** `lua/cargdev/core/options.lua` lines 54 and 105 + +**Issue:** `foldmethod` is set to "syntax" then "indent". + +**Recommendation:** +```lua +-- Choose one method or make it filetype-specific +-- "indent" is generally faster than "syntax" +``` + +**Priority:** ๐ŸŸก Medium + +--- + +## โœจ Missing Features & Enhancements + +### 15. **Missing Which-Key Integration** +**Location:** `lua/cargdev/plugins/which-key.lua` exists but keymaps may not be registered + +**Recommendation:** +```lua +-- Ensure all keymaps use proper descriptions for which-key +-- Add group names for better organization +-- Example: { desc = "Copilot: Accept", group = "Copilot" } +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 16. **No Auto-Format on Save** +**Location:** Formatting plugin exists but no autocmd for auto-format + +**Recommendation:** +```lua +-- Add to formatting.lua or create autocmd: +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*", + callback = function() + if vim.bo.filetype ~= "" then + vim.lsp.buf.format({ async = false }) + end + end, +}) +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 17. **Missing Diagnostic Float on Hover** +**Location:** LSP config + +**Issue:** `K` shows documentation, but diagnostic hover could be enhanced. + +**Recommendation:** +```lua +-- Add diagnostic hover enhancement: +vim.api.nvim_create_autocmd("CursorHold", { + callback = function() + vim.diagnostic.open_float(nil, { focus = false }) + end, +}) +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 18. **No Buffer Close Confirmation for Unsaved Changes** +**Location:** Buffer management + +**Recommendation:** +```lua +-- Add safe buffer close: +keymap.set("n", "bd", function() + if vim.bo.modified then + vim.ui.select({ "Save", "Discard", "Cancel" }, { + prompt = "Buffer has unsaved changes:" + }, function(choice) + if choice == "Save" then + vim.cmd("w") + vim.cmd("bd") + elseif choice == "Discard" then + vim.cmd("bd!") + end + end) + else + vim.cmd("bd") + end +end, { desc = "Close buffer (safe)" }) +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 19. **Missing Quickfix Navigation Enhancements** +**Location:** Quickfix/Trouble integration + +**Recommendation:** +```lua +-- Add quickfix navigation: +keymap.set("n", "qn", ":cnext", { desc = "Next quickfix" }) +keymap.set("n", "qp", ":cprev", { desc = "Previous quickfix" }) +keymap.set("n", "qq", ":cclose", { desc = "Close quickfix" }) +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 20. **No Project Root Detection Enhancement** +**Location:** Project config + +**Recommendation:** +```lua +-- Add better project root detection using: +-- - .git directory +-- - package.json, Cargo.toml, etc. +-- - Consider using nvim-lspconfig's root_dir patterns +``` + +**Priority:** ๐ŸŸข Low + +--- + +## ๐Ÿ“š Documentation Updates + +### 21. **README.md is Outdated** +**Location:** Root `README.md` + +**Issue:** README contains Tmux/Vim keymaps, not Neovim-specific information. + +**Recommendation:** +- Update README with: + - Neovim version requirements + - Installation instructions + - Plugin list + - Keymap reference (link to keyboard_mappings.md) + - Configuration structure + - Troubleshooting section + +**Priority:** ๐ŸŸก Medium + +--- + +### 22. **Missing Keymap Documentation** +**Location:** Various keymap files + +**Issue:** Not all keymaps are documented in `keyboard_mappings.md`. + +**Recommendation:** +- Update `keyboard_mappings.md` with all current keymaps +- Organize by category +- Add search functionality or table of contents + +**Priority:** ๐ŸŸก Medium + +--- + +### 23. **Plugin Documentation Missing** +**Location:** No central plugin documentation + +**Recommendation:** +- Create `PLUGINS.md` documenting: + - What each plugin does + - Why it's included + - Configuration highlights + - Dependencies + +**Priority:** ๐ŸŸข Low + +--- + +## ๐Ÿ”Œ Plugin Management + +### 24. **Potential Plugin Redundancy** +**Location:** Multiple plugins for similar functionality + +**Examples:** +- `telescope.lua` and `snacks.lua` - Both are file pickers (Snacks is replacement) +- `substitute.lua` and native Neovim features + +**Recommendation:** +- Review if Telescope is still needed after Snacks migration +- Document which plugins are being phased out + +**Priority:** ๐ŸŸก Medium + +--- + +### 25. **Missing Plugin Health Checks** +**Location:** No health check automation + +**Recommendation:** +```lua +-- Add to init.lua or create health check: +vim.api.nvim_create_user_command("CheckConfig", function() + vim.cmd("checkhealth") + -- Add custom checks for: + -- - Required plugins installed + -- - LSP servers available + -- - Keymap conflicts +end, {}) +``` + +**Priority:** ๐ŸŸข Low + +--- + +### 26. **No Plugin Update Reminder** +**Location:** Lazy.nvim config + +**Recommendation:** +```lua +-- Enable update notifications: +require("lazy").setup({ + checker = { + enabled = true, + notify = true, -- Change from false to true + frequency = 3600, -- Check every hour + }, +}) +``` + +**Priority:** ๐ŸŸข Low + +--- + +## ๐Ÿ”’ Security & Best Practices + +### 27. **Modeline Disabled (Good)** +**Status:** โœ… Already disabled in `options.lua` line 59 + +**Note:** Good security practice, keep it disabled. + +--- + +### 28. **Missing Secure Defaults for Netrw** +**Status:** โœ… Netrw is disabled (good) + +**Note:** Consider documenting why it's disabled. + +--- + +### 29. **Environment Variable Usage** +**Location:** `general.lua` line 19 + +**Issue:** Uses `vim.env.IDEA_DIR` without validation. + +**Recommendation:** +```lua +-- Add validation: +local vault_path = vim.env.IDEA_DIR +if not vault_path or vault_path == "" then + return -- Don't set up Obsidian links if not configured +end +``` + +**Priority:** ๐ŸŸข Low + +--- + +## ๐ŸŽฏ Quick Wins + +### 30. **Add Statusline Customization** +**Location:** `lualine.lua` + +**Recommendation:** +- Add git branch indicator +- Add LSP status +- Add file encoding +- Add word count for markdown files + +**Priority:** ๐ŸŸข Low + +--- + +### 31. **Add File Explorer Enhancements** +**Location:** `nvim-tree.lua` + +**Recommendation:** +- Add file creation from explorer +- Add better file preview +- Add git status indicators + +**Priority:** ๐ŸŸข Low + +--- + +### 32. **Add Better Error Handling** +**Location:** Various files + +**Recommendation:** +```lua +-- Wrap plugin requires in pcall: +local ok, plugin = pcall(require, "plugin-name") +if not ok then + vim.notify("Plugin failed to load: plugin-name", vim.log.levels.WARN) + return +end +``` + +**Priority:** ๐ŸŸก Medium + +--- + +### 33. **Add Configuration Validation** +**Location:** Core init + +**Recommendation:** +```lua +-- Add startup validation: +local function validate_config() + -- Check Neovim version + if vim.fn.has("nvim-0.9") == 0 then + vim.notify("Neovim 0.9+ required", vim.log.levels.ERROR) + end + -- Check required commands + -- Check required plugins +end +``` + +**Priority:** ๐ŸŸข Low + +--- + +## ๐Ÿ“Š Summary Statistics + +- **Total Issues Found:** 32 +- **Critical (High Priority):** 2 (2 fixed) +- **Medium Priority:** 12 +- **Low Priority:** 18 +- **Already Fixed/Good:** 2 + +--- + +## ๐Ÿš€ Recommended Action Plan + +### Phase 1: Critical Fixes (Do First) +1. โœ… Fix duplicate git conflict keymaps (FIXED) +2. โœ… Fix duplicate Copilot keymaps (FIXED) +3. Resolve substitute/session keymap conflict + +### Phase 2: Code Quality (Do Next) +4. Remove temporary files +5. Clean up commented code +6. Fix duplicate settings (synmaxcol, foldmethod) +7. Standardize keymap descriptions + +### Phase 3: Enhancements (Do When Time Permits) +8. Add auto-format on save +9. Update documentation +10. Add missing keymaps (quickfix navigation) +11. Enhance error handling + +### Phase 4: Polish (Nice to Have) +12. Add configuration validation +13. Enhance statusline +14. Add plugin documentation +15. Improve project root detection + +--- + +## ๐Ÿ“ Notes + +- Most issues are low-priority and don't affect functionality +- Configuration is generally well-organized +- Keymap conflicts are the main concern +- Documentation could be more comprehensive +- Performance optimizations are minor but worthwhile + +--- + +## ๐Ÿ”„ Maintenance Recommendations + +1. **Regular Audits:** Review keymaps quarterly for conflicts +2. **Plugin Updates:** Keep plugins updated but test before updating +3. **Documentation:** Update docs when adding new features +4. **Code Cleanup:** Remove commented code during refactoring +5. **Testing:** Test configuration after major changes + +--- + +**Last Updated:** 2024 +**Next Review:** Quarterly or after major changes diff --git a/README.md b/README.md index 5331b79..68f9a4f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +# Neovim Configuration + +> **๐Ÿ“‹ Documentation:** +> - **[IMPROVEMENTS.md](./IMPROVEMENTS.md)** - Comprehensive analysis of configuration improvements and recommendations +> - **[keyboard_mappings.md](./keyboard_mappings.md)** - Complete keymap reference +> - **[NATIVE_AUTO_WRAPPER_GUIDE.md](./NATIVE_AUTO_WRAPPER_GUIDE.md)** - Text wrapping configuration guide + +--- + # Vim and Tmux Keymaps ## Tmux Keymaps diff --git a/lua/cargdev/core/keymaps/copilot.lua b/lua/cargdev/core/keymaps/copilot.lua index 3d9f8fd..c3290bb 100644 --- a/lua/cargdev/core/keymaps/copilot.lua +++ b/lua/cargdev/core/keymaps/copilot.lua @@ -1,18 +1,86 @@ -- Copilot keymaps local keymap = vim.keymap +-- Helper function to safely get Copilot modules +local function get_copilot_panel() + local ok, panel = pcall(require, "copilot.panel") + return ok and panel or nil +end + +local function get_copilot_suggestion() + local ok, suggestion = pcall(require, "copilot.suggestion") + return ok and suggestion or nil +end + -- Copilot panel and status keymap.set("n", "cp", ":Copilot panel", { desc = "Copilot: Open copilot panel" }) keymap.set("n", "cd", ":Copilot disable", { desc = "Copilot: Disable" }) keymap.set("n", "ce", ":Copilot enable", { desc = "Copilot: Enable" }) keymap.set("n", "cs", ":Copilot status", { desc = "Copilot: Status" }) --- Copilot suggestion navigation (insert mode) --- These are configured in copilot.lua but documented here for reference: --- ] - Next suggestion --- [ - Previous suggestion --- - Accept suggestion --- - Dismiss suggestion +-- Copilot panel keymaps +keymap.set("n", "[[", function() + local panel = get_copilot_panel() + if panel and panel.is_open() then + panel.jump_prev() + end +end, { desc = "Copilot: Jump to previous suggestion in panel" }) + +keymap.set("n", "]]", function() + local panel = get_copilot_panel() + if panel and panel.is_open() then + panel.jump_next() + end +end, { desc = "Copilot: Jump to next suggestion in panel" }) + +keymap.set("n", "", function() + local panel = get_copilot_panel() + if panel and panel.is_open() then + panel.accept() + end +end, { desc = "Copilot: Accept suggestion in panel" }) + +keymap.set("n", "gr", function() + local panel = get_copilot_panel() + if panel and panel.is_open() then + panel.refresh() + end +end, { desc = "Copilot: Refresh panel" }) + +keymap.set("n", "", ":Copilot panel", { desc = "Copilot: Open panel" }) + +-- Copilot suggestion keymaps (insert mode) +keymap.set("i", "", function() + local suggestion = get_copilot_suggestion() + if suggestion and suggestion.is_visible() then + suggestion.accept() + else + -- Feed Tab through so nvim-cmp can handle it for completion menu/snippets + -- Use 't' flag to avoid remapping, 'n' flag for normal mode keycodes + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "nt") + end +end, { desc = "Copilot: Accept suggestion" }) + +keymap.set("i", "]", function() + local suggestion = get_copilot_suggestion() + if suggestion and suggestion.is_visible() then + suggestion.next() + end +end, { desc = "Copilot: Next suggestion" }) + +keymap.set("i", "[", function() + local suggestion = get_copilot_suggestion() + if suggestion and suggestion.is_visible() then + suggestion.prev() + end +end, { desc = "Copilot: Previous suggestion" }) + +keymap.set("i", "", function() + local suggestion = get_copilot_suggestion() + if suggestion and suggestion.is_visible() then + suggestion.dismiss() + end +end, { desc = "Copilot: Dismiss suggestion" }) -- CodeCompanion keymaps keymap.set("n", "cc", ":CodeCompanion", { desc = "CodeCompanion: Open CodeCompanion" }) diff --git a/lua/cargdev/core/keymaps/general.lua b/lua/cargdev/core/keymaps/general.lua index 1f2eb12..dabbe15 100644 --- a/lua/cargdev/core/keymaps/general.lua +++ b/lua/cargdev/core/keymaps/general.lua @@ -7,9 +7,12 @@ local opts = { noremap = true, silent = true } -- ============================================================================= -- General keymaps -keymap.set("i", "jk", "", opts) -- Exit insert mode with jk +-- Changed from "jk" to "jj" to avoid conflicts when typing words containing 'j' followed by other letters +-- "jj" is much less likely to appear in normal typing and won't interfere +keymap.set("i", "jj", "", opts) -- Exit insert mode with jj keymap.set("n", "nh", ":nohl", opts) -- Clear search highlights -keymap.set("n", "x", '"_x', opts) -- Delete character without copying into register +-- Removed: keymap.set("n", "x", '"_x', opts) -- Delete character without copying into register +-- This was causing single character deletions to not be copied to the default register -- Save and quit (additional) keymap.set("n", "Q", ":qa!", { desc = "Quit all" }) diff --git a/lua/cargdev/core/keymaps/gitconflict.lua b/lua/cargdev/core/keymaps/gitconflict.lua index aac7b04..dcbe216 100644 --- a/lua/cargdev/core/keymaps/gitconflict.lua +++ b/lua/cargdev/core/keymaps/gitconflict.lua @@ -3,7 +3,7 @@ local keymap = vim.keymap keymap.set("n", "]x", "(git-conflict-next-conflict)", { desc = "Go to next git conflict" }) keymap.set("n", "[x", "(git-conflict-prev-conflict)", { desc = "Go to previous git conflict" }) -keymap.set("n", "coo", "(git-conflict-ours)", { desc = "Choose ours (git conflict)" }) +keymap.set("n", "co", "(git-conflict-ours)", { desc = "Choose ours (git conflict)" }) keymap.set("n", "ct", "(git-conflict-theirs)", { desc = "Choose theirs (git conflict)" }) keymap.set("n", "cb", "(git-conflict-both)", { desc = "Choose both (git conflict)" }) keymap.set("n", "c0", "(git-conflict-none)", { desc = "Choose none (git conflict)" }) diff --git a/lua/cargdev/core/keymaps/personal.lua b/lua/cargdev/core/keymaps/personal.lua index aa9cf45..8c4dabe 100644 --- a/lua/cargdev/core/keymaps/personal.lua +++ b/lua/cargdev/core/keymaps/personal.lua @@ -78,7 +78,7 @@ keymap.set("n", "", ":resize -5", { noremap = true, silent = true }) keymap.set("n", "pr", ":RunProject", { desc = "Run Project" }) keymap.set("n", "pd", ":DebugProject", { desc = "Debug Project" }) --- Copilot Chat +-- Copilot Chat (all Copilot keymaps moved to lua/cargdev/core/keymaps/copilot.lua) keymap.set("v", "zn", ":CopilotChatRename", { desc = "Rename variable (Copilot Chat)" }) keymap.set("n", "zc", ":CopilotChat", { desc = "Open Copilot Chat" }) keymap.set("v", "ze", ":CopilotChatExplain", { desc = "Explain code (Copilot Chat)" }) @@ -87,10 +87,6 @@ keymap.set("v", "zf", ":CopilotChatFix", { desc = "Fix code issues ( keymap.set("v", "zo", ":CopilotChatOptimize", { desc = "Optimize code (Copilot Chat)" }) keymap.set("v", "zd", ":CopilotChatDocs", { desc = "Generate docs (Copilot Chat)" }) --- Copilot -keymap.set("n", "cp", ":Copilot panel", { desc = "Copilot: Open copilot panel" }) -keymap.set("n", "ce", ":CopilotChatExplain", { desc = "Copilot Chat: Explain code" }) - -- Paste HTML as Markdown using pandoc keymap.set("n", "p", function() vim.cmd("read !pbpaste -Prefer html | pandoc -f html -t gfm") diff --git a/lua/cargdev/core/keymaps/plugins.lua b/lua/cargdev/core/keymaps/plugins.lua index 9034db4..c9c30c7 100644 --- a/lua/cargdev/core/keymaps/plugins.lua +++ b/lua/cargdev/core/keymaps/plugins.lua @@ -59,14 +59,7 @@ keymap.set("n", "sa", "lua require('nvim-surround').surround_add()< keymap.set("n", "sd", "lua require('nvim-surround').surround_delete()", { desc = "Delete surrounding" }) keymap.set("n", "sr", "lua require('nvim-surround').surround_replace()", { desc = "Replace surrounding" }) --- Git conflicts -keymap.set("n", "]x", "(git-conflict-next-conflict)", { desc = "Go to next git conflict" }) -keymap.set("n", "[x", "(git-conflict-prev-conflict)", { desc = "Go to previous git conflict" }) -keymap.set("n", "co", "(git-conflict-ours)", { desc = "Choose ours (git conflict)" }) -keymap.set("n", "ct", "(git-conflict-theirs)", { desc = "Choose theirs (git conflict)" }) -keymap.set("n", "cb", "(git-conflict-both)", { desc = "Choose both (git conflict)" }) -keymap.set("n", "c0", "(git-conflict-none)", { desc = "Choose none (git conflict)" }) -keymap.set("n", "cq", "(git-conflict-list)", { desc = "List all git conflicts" }) +-- Git conflicts (moved to lua/cargdev/core/keymaps/gitconflict.lua) -- LeetCode keymap.set("n", "lr", "Leet run", { desc = "LeetCode: Run Code" }) diff --git a/lua/cargdev/core/options.lua b/lua/cargdev/core/options.lua index e05ce14..17c376e 100644 --- a/lua/cargdev/core/options.lua +++ b/lua/cargdev/core/options.lua @@ -76,20 +76,20 @@ opt.signcolumn = "yes" -- Always show sign column -- ============================================================================= -- Text wrapping settings -opt.wrap = true -- Enable line wrapping +opt.wrap = true -- Enable visual line wrapping (wraps based on window width) opt.linebreak = true -- Break lines at word boundaries opt.breakindent = true -- Preserve indentation in wrapped lines opt.showbreak = "โ†ช " -- Show break indicator opt.breakindentopt = "shift:2" -- Indent wrapped lines by 2 spaces -- Text width and formatting -opt.textwidth = 80 -- Set text width for auto-wrapping -opt.colorcolumn = "80" -- Show column at 80 characters -opt.formatoptions = "jcroqlnt" -- Format options for auto-wrapping +opt.textwidth = 0 -- Disable hard wrapping (0 = no limit, wraps based on window width) +opt.colorcolumn = "" -- Disable color column (or set to a high value if you want a guide) +opt.formatoptions = "jcroqln" -- Format options (removed 't' to disable auto-wrap based on textwidth) --- Auto-wrap specific settings -opt.formatoptions:append("t") -- Auto-wrap text using textwidth -opt.formatoptions:append("c") -- Auto-wrap comments using textwidth +-- Format options settings +-- Note: 't' option removed - we want visual wrapping only, not hard line breaks +opt.formatoptions:append("c") -- Auto-wrap comments using textwidth (only applies if textwidth > 0) opt.formatoptions:append("r") -- Auto-wrap comments when pressing Enter opt.formatoptions:append("o") -- Auto-wrap comments when pressing 'o' or 'O' opt.formatoptions:append("q") -- Allow formatting of comments with 'gq' @@ -214,33 +214,34 @@ end -- ============================================================================= -- Consolidated auto-wrapping configuration +-- Note: textwidth is set to 0 globally to allow visual wrapping based on window width vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() local filetype = vim.bo.filetype local opt = vim.opt_local - -- Text/documentation files + -- Text/documentation files - visual wrapping only (no hard breaks) if vim.tbl_contains({ "text", "markdown", "gitcommit", "mail", "help", "man" }, filetype) then - opt.textwidth = filetype == "help" or filetype == "man" and 78 or 80 + opt.textwidth = 0 -- Disable hard wrapping, use visual wrapping based on window width opt.wrap = true opt.linebreak = true - opt.formatoptions:append("t") -- Auto-wrap text + -- Removed 't' option - we want visual wrapping only, not hard line breaks end - -- Code files + -- Code files - visual wrapping only (no hard breaks) if vim.tbl_contains({ "lua", "javascript", "typescript", "python", "java", "cpp", "c", "rust", "go" }, filetype) then - opt.textwidth = 100 -- Longer lines for code - opt.formatoptions:append("c") -- Auto-wrap comments + opt.textwidth = 0 -- Disable hard wrapping, use visual wrapping based on window width + opt.formatoptions:append("c") -- Auto-wrap comments (only if textwidth > 0, so this won't apply) opt.formatoptions:append("r") -- Auto-wrap comments with leader opt.formatoptions:append("o") -- Auto-wrap comments with 'o' opt.formatoptions:append("q") -- Allow formatting of comments with 'gq' end - -- Configuration files + -- Configuration files - visual wrapping only (no hard breaks) if vim.tbl_contains({ "conf", "config", "ini", "toml", "yaml", "json" }, filetype) then - opt.textwidth = 80 - opt.formatoptions:append("c") -- Auto-wrap comments + opt.textwidth = 0 -- Disable hard wrapping, use visual wrapping based on window width + opt.formatoptions:append("c") -- Auto-wrap comments (only if textwidth > 0, so this won't apply) end end, }) diff --git a/lua/cargdev/plugins/copilot.lua b/lua/cargdev/plugins/copilot.lua index 37a0f5f..1c174d8 100644 --- a/lua/cargdev/plugins/copilot.lua +++ b/lua/cargdev/plugins/copilot.lua @@ -8,13 +8,6 @@ return { panel = { enabled = true, auto_refresh = false, - keymap = { - jump_prev = "[[", - jump_next = "]]", - accept = "", - refresh = "gr", - open = "", - }, layout = { position = "bottom", -- | top | left | right ratio = 0.4, @@ -24,14 +17,6 @@ return { enabled = true, auto_trigger = true, -- Enable auto-trigger suggestions as you type debounce = 75, - keymap = { - accept = "", - accept_word = false, - accept_line = false, - next = "]", -- Use leader key for next suggestion - prev = "[", -- Use leader key for previous suggestion - dismiss = "", - }, }, filetypes = { markdown = true, @@ -41,11 +26,27 @@ return { hgcommit = true, svn = true, cvs = true, + tex = false, -- Disable Copilot for LaTeX files by default ["."] = true, }, copilot_node_command = "node", -- Node.js version must be > 16.x server_opts_overrides = {}, }) + + -- Disable Copilot when opening .tex files + vim.api.nvim_create_autocmd({ "FileType", "BufEnter" }, { + pattern = "tex", + callback = function() + -- Safely dismiss any active suggestions + local ok, suggestion = pcall(require, "copilot.suggestion") + if ok and suggestion and suggestion.is_visible() then + suggestion.dismiss() + end + -- Disable Copilot for this buffer + vim.cmd("Copilot disable") + end, + desc = "Disable Copilot for LaTeX files", + }) end, }, { diff --git a/lua/cargdev/plugins/lualine.lua b/lua/cargdev/plugins/lualine.lua index 3698644..0c3ecee 100644 --- a/lua/cargdev/plugins/lualine.lua +++ b/lua/cargdev/plugins/lualine.lua @@ -49,12 +49,44 @@ return { }, } + -- Custom word/character counter function + local function word_count() + -- Skip for very large files to avoid performance issues + local line_count = vim.api.nvim_buf_line_count(0) + if line_count > 10000 then + return "" + end + + local words = 0 + local chars = 0 + + -- Get all lines at once for better performance + local all_lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + + for _, line in ipairs(all_lines) do + if line and #line > 0 then + -- Count words (non-whitespace sequences) + for _ in line:gmatch("%S+") do + words = words + 1 + end + -- Count characters (excluding newline) + chars = chars + #line + end + end + + -- Format: show words and characters + return string.format("%d words, %d chars", words, chars) + end + -- configure lualine with modified theme lualine.setup({ options = { theme = my_lualine_theme, }, sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename" }, lualine_x = { { lazy_status.updates, @@ -65,6 +97,22 @@ return { { "fileformat" }, { "filetype" }, }, + lualine_y = { "progress" }, + lualine_z = { + { + word_count, + color = { fg = colors.fg }, + }, + { "location" }, + }, + }, + inactive_sections = { + lualine_a = { "filename" }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = { "location" }, }, }) end, diff --git a/lua/cargdev/plugins/nvim-cmp.lua b/lua/cargdev/plugins/nvim-cmp.lua index b79ea05..a236f85 100644 --- a/lua/cargdev/plugins/nvim-cmp.lua +++ b/lua/cargdev/plugins/nvim-cmp.lua @@ -47,17 +47,17 @@ return { [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.confirm({ select = false }), - -- Tab to accept Copilot suggestions, fallback to snippet expansion + -- Tab for completion menu and snippet expansion + -- Note: Copilot suggestion acceptance is handled in keymaps/copilot.lua [""] = cmp.mapping(function(fallback) + -- Handle nvim-cmp completion menu if cmp.visible() then local entry = cmp.get_selected_entry() -- If Copilot suggestion is available and selected, accept it if entry and entry.source.name == "copilot" then cmp.confirm({ select = true }) else - -- Check if we can find a Copilot entry in the completion menu - -- Since Copilot has high priority (900), it's likely near the top - -- Just confirm the current selection (Copilot will be selected if available) + -- Confirm the current selection cmp.confirm({ select = true }) end elseif luasnip.expand_or_jumpable() then