atxtechbro / atxtechbro/dotfiles

Reassign nvim-cmp Tab functionality to prioritize GitHub Copilot

Open
#245 0 comments 1 reaction 1 assignee Assigned to @Copilot View on GitHub
configuration enhancement
Dominant language
Shell
Stars
27
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## Feature Request: Prioritize GitHub Copilot Tab Completion

### Current Behavior
Currently, our Neovim configuration assigns the Tab key to nvim-cmp functionality:
- Selecting next item in completion menu
- Expanding/navigating snippets via LuaSnip
- Default tab behavior as fallback

Meanwhile, GitHub Copilot's suggestion acceptance is mapped to `` to avoid conflicts.

### Proposed Change
Reassign the nvim-cmp Tab functionality to another key combination and restore Tab as the primary key for accepting GitHub Copilot suggestions.

### Rationale
GitHub Copilot's suggestion acceptance is more valuable in daily coding workflows than nvim-cmp's Tab navigation. The muscle memory of pressing Tab to accept AI suggestions is strong for many developers, and the current setup creates friction.

### Implementation Options

#### Option 1: Swap the Key Mappings
```lua
-- Disable Copilot's tab map initially (keep this line)
vim.g.copilot_no_tab_map = true

-- Map Tab to accept Copilot suggestions
vim.api.nvim_set_keymap('i', '', 'copilot#Accept("")', { expr = true, silent = true })

-- Move nvim-cmp's Tab functionality to Ctrl+J
cmp.setup({
-- other settings...
mapping = cmp.mapping.preset.insert({
-- other mappings...
[''] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
-- Keep S-Tab as is for previous item
}),
})
```

#### Option 2: Make Tab Context-Aware Between Copilot and nvim-cmp
```lua
-- A more complex but potentially more powerful approach
vim.api.nvim_set_keymap('i', '', 'v:lua.tab_complete()', { expr = true, silent = true })

-- Define the tab_complete function in your init.lua
_G.tab_complete = function()
local copilot_keys = vim.fn['copilot#GetDisplayedSuggestion']()

if copilot_keys.text ~= '' then
return vim.fn['copilot#Accept']("")
elseif require('cmp').visible() then
return require('cmp').mapping.select_next_item()({ behavior = require('cmp').SelectBehavior.Select })
elseif require('luasnip').expand_or_jumpable() then
return require('luasnip').expand_or_jump()
else
return ""
end
end
```

### Files to Update
1. `nvim/lua/plugins/copilot.lua` - Update Copilot key mappings
2. `nvim/init.lua` - Update nvim-cmp configuration in the cmp_setup function
3. `nvim/nvim-cheatsheet.md` - Update documentation to reflect new key mappings
4. `nvim/copilot-cheatsheet.md` - Update with new Tab mapping information

### Benefits
- Aligns with the natural expectation that Tab accepts the visible suggestion
- Improves developer experience with GitHub Copilot
- Reduces cognitive load by using the standard Tab key for its most common modern use case

### Drawbacks
- Requires users to learn a new key combination for nvim-cmp navigation
- May require some adjustment period

### Implementation Priority
High - This would significantly improve the GitHub Copilot experience while requiring minimal changes to the configuration.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.