Skip to content

Commit 173c015

Browse files
skoch13tris203
andauthored
docs: update expr mapping for <c-i>/tab (#47)
Co-authored-by: tris203 <[email protected]>
1 parent 4d79a1f commit 173c015

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,43 @@ return {
2828
vim.g.copilot_nes_debounce = 500
2929
vim.lsp.enable("copilot_ls")
3030
vim.keymap.set("n", "<tab>", function()
31-
-- Try to jump to the start of the suggestion edit.
32-
-- If already at the start, then apply the pending suggestion and jump to the end of the edit.
33-
local _ = require("copilot-lsp.nes").walk_cursor_start_edit()
34-
or (
35-
require("copilot-lsp.nes").apply_pending_nes() and require("copilot-lsp.nes").walk_cursor_end_edit()
36-
)
37-
end)
31+
local bufnr = vim.api.nvim_get_current_buf()
32+
local state = vim.b[bufnr].nes_state
33+
if state then
34+
-- Try to jump to the start of the suggestion edit.
35+
-- If already at the start, then apply the pending suggestion and jump to the end of the edit.
36+
local _ = require("copilot-lsp.nes").walk_cursor_start_edit()
37+
or (
38+
require("copilot-lsp.nes").apply_pending_nes()
39+
and require("copilot-lsp.nes").walk_cursor_end_edit()
40+
)
41+
return nil
42+
else
43+
-- Resolving the terminal's inability to distinguish between `TAB` and `<C-i>` in normal mode
44+
return "<C-i>"
45+
end
46+
end, { desc = "Accept Copilot NES suggestion", expr = true })
3847
end,
3948
}
4049
```
4150

42-
4351
#### Clearing suggestions with Escape
4452

4553
You can map the `<Esc>` key to clear suggestions while preserving its other functionality:
4654

4755
```lua
4856
-- Clear copilot suggestion with Esc if visible, otherwise preserve default Esc behavior
4957
vim.keymap.set("n", "<esc>", function()
50-
if not require('copilot-lsp.nes').clear() then
58+
if not require("copilot-lsp.nes").clear() then
5159
-- fallback to other functionality
5260
end
5361
end, { desc = "Clear Copilot suggestion or fallback" })
5462
```
5563

5664
## Default Configuration
5765

58-
5966
### NES (Next Edit Suggestion) Smart Clearing
67+
6068
You don’t need to configure anything, but you can customize the defaults:
6169
`move_count_threshold` is the most important. It controls how many cursor moves happen before suggestions are cleared. Higher = slower to clear.
6270

@@ -68,7 +76,6 @@ require('copilot-lsp').setup({
6876
})
6977
```
7078

71-
7279
### Blink Integration
7380

7481
```lua

0 commit comments

Comments
 (0)