Fix keymap conflicts and add improvements

- Fix duplicate git conflict keymaps (centralized in gitconflict.lua)
- Fix duplicate Copilot keymaps (centralized in copilot.lua)
- Change insert mode escape from 'jk' to 'jj' to avoid typing conflicts
- Add word counter to statusline (lualine)
- Disable Copilot by default for .tex files
- Remove textwidth limits for visual wrapping based on window width
- Add comprehensive improvements documentation (IMPROVEMENTS.md)
- Update README with links to documentation
This commit is contained in:
Carlos Gutierrez
2026-01-10 16:31:17 -05:00
parent 97795e90b3
commit 0066ac1441
11 changed files with 820 additions and 57 deletions

View File

@@ -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", "<leader>cp", ":Copilot panel<CR>", { desc = "Copilot: Open copilot panel" })
keymap.set("n", "<leader>cd", ":Copilot disable<CR>", { desc = "Copilot: Disable" })
keymap.set("n", "<leader>ce", ":Copilot enable<CR>", { desc = "Copilot: Enable" })
keymap.set("n", "<leader>cs", ":Copilot status<CR>", { desc = "Copilot: Status" })
-- Copilot suggestion navigation (insert mode)
-- These are configured in copilot.lua but documented here for reference:
-- <leader>] - Next suggestion
-- <leader>[ - Previous suggestion
-- <M-l> - Accept suggestion
-- <C-]> - 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", "<CR>", 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", "<M-CR>", ":Copilot panel<CR>", { desc = "Copilot: Open panel" })
-- Copilot suggestion keymaps (insert mode)
keymap.set("i", "<Tab>", 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("<Tab>", true, false, true), "nt")
end
end, { desc = "Copilot: Accept suggestion" })
keymap.set("i", "<leader>]", function()
local suggestion = get_copilot_suggestion()
if suggestion and suggestion.is_visible() then
suggestion.next()
end
end, { desc = "Copilot: Next suggestion" })
keymap.set("i", "<leader>[", function()
local suggestion = get_copilot_suggestion()
if suggestion and suggestion.is_visible() then
suggestion.prev()
end
end, { desc = "Copilot: Previous suggestion" })
keymap.set("i", "<C-]>", 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", "<leader>cc", ":CodeCompanion<CR>", { desc = "CodeCompanion: Open CodeCompanion" })

View File

@@ -7,9 +7,12 @@ local opts = { noremap = true, silent = true }
-- =============================================================================
-- General keymaps
keymap.set("i", "jk", "<ESC>", 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", "<ESC>", opts) -- Exit insert mode with jj
keymap.set("n", "<leader>nh", ":nohl<CR>", 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", "<leader>Q", ":qa!<CR>", { desc = "Quit all" })

View File

@@ -3,7 +3,7 @@ local keymap = vim.keymap
keymap.set("n", "]x", "<Plug>(git-conflict-next-conflict)", { desc = "Go to next git conflict" })
keymap.set("n", "[x", "<Plug>(git-conflict-prev-conflict)", { desc = "Go to previous git conflict" })
keymap.set("n", "<leader>coo", "<Plug>(git-conflict-ours)", { desc = "Choose ours (git conflict)" })
keymap.set("n", "<leader>co", "<Plug>(git-conflict-ours)", { desc = "Choose ours (git conflict)" })
keymap.set("n", "<leader>ct", "<Plug>(git-conflict-theirs)", { desc = "Choose theirs (git conflict)" })
keymap.set("n", "<leader>cb", "<Plug>(git-conflict-both)", { desc = "Choose both (git conflict)" })
keymap.set("n", "<leader>c0", "<Plug>(git-conflict-none)", { desc = "Choose none (git conflict)" })

View File

@@ -78,7 +78,7 @@ keymap.set("n", "<C-j>", ":resize -5<CR>", { noremap = true, silent = true })
keymap.set("n", "<leader>pr", ":RunProject<CR>", { desc = "Run Project" })
keymap.set("n", "<leader>pd", ":DebugProject<CR>", { desc = "Debug Project" })
-- Copilot Chat
-- Copilot Chat (all Copilot keymaps moved to lua/cargdev/core/keymaps/copilot.lua)
keymap.set("v", "<leader>zn", ":CopilotChatRename<CR>", { desc = "Rename variable (Copilot Chat)" })
keymap.set("n", "<leader>zc", ":CopilotChat<CR>", { desc = "Open Copilot Chat" })
keymap.set("v", "<leader>ze", ":CopilotChatExplain<CR>", { desc = "Explain code (Copilot Chat)" })
@@ -87,10 +87,6 @@ keymap.set("v", "<leader>zf", ":CopilotChatFix<CR>", { desc = "Fix code issues (
keymap.set("v", "<leader>zo", ":CopilotChatOptimize<CR>", { desc = "Optimize code (Copilot Chat)" })
keymap.set("v", "<leader>zd", ":CopilotChatDocs<CR>", { desc = "Generate docs (Copilot Chat)" })
-- Copilot
keymap.set("n", "<leader>cp", ":Copilot panel<CR>", { desc = "Copilot: Open copilot panel" })
keymap.set("n", "<leader>ce", ":CopilotChatExplain<CR>", { desc = "Copilot Chat: Explain code" })
-- Paste HTML as Markdown using pandoc
keymap.set("n", "<leader>p", function()
vim.cmd("read !pbpaste -Prefer html | pandoc -f html -t gfm")

View File

@@ -59,14 +59,7 @@ keymap.set("n", "<leader>sa", "<cmd>lua require('nvim-surround').surround_add()<
keymap.set("n", "<leader>sd", "<cmd>lua require('nvim-surround').surround_delete()<cr>", { desc = "Delete surrounding" })
keymap.set("n", "<leader>sr", "<cmd>lua require('nvim-surround').surround_replace()<cr>", { desc = "Replace surrounding" })
-- Git conflicts
keymap.set("n", "]x", "<Plug>(git-conflict-next-conflict)", { desc = "Go to next git conflict" })
keymap.set("n", "[x", "<Plug>(git-conflict-prev-conflict)", { desc = "Go to previous git conflict" })
keymap.set("n", "<leader>co", "<Plug>(git-conflict-ours)", { desc = "Choose ours (git conflict)" })
keymap.set("n", "<leader>ct", "<Plug>(git-conflict-theirs)", { desc = "Choose theirs (git conflict)" })
keymap.set("n", "<leader>cb", "<Plug>(git-conflict-both)", { desc = "Choose both (git conflict)" })
keymap.set("n", "<leader>c0", "<Plug>(git-conflict-none)", { desc = "Choose none (git conflict)" })
keymap.set("n", "<leader>cq", "<Plug>(git-conflict-list)", { desc = "List all git conflicts" })
-- Git conflicts (moved to lua/cargdev/core/keymaps/gitconflict.lua)
-- LeetCode
keymap.set("n", "<leader>lr", "<cmd>Leet run<CR>", { desc = "LeetCode: Run Code" })

View File

@@ -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,
})

View File

@@ -8,13 +8,6 @@ return {
panel = {
enabled = true,
auto_refresh = false,
keymap = {
jump_prev = "[[",
jump_next = "]]",
accept = "<CR>",
refresh = "gr",
open = "<M-CR>",
},
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 = "<M-l>",
accept_word = false,
accept_line = false,
next = "<leader>]", -- Use leader key for next suggestion
prev = "<leader>[", -- Use leader key for previous suggestion
dismiss = "<C-]>",
},
},
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,
},
{

View File

@@ -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,

View File

@@ -47,17 +47,17 @@ return {
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
["<C-e>"] = cmp.mapping.abort(), -- close completion window
["<CR>"] = 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
["<Tab>"] = 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