@@ -28,35 +28,43 @@ return {
28
28
vim .g .copilot_nes_debounce = 500
29
29
vim .lsp .enable (" copilot_ls" )
30
30
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 })
38
47
end ,
39
48
}
40
49
```
41
50
42
-
43
51
#### Clearing suggestions with Escape
44
52
45
53
You can map the ` <Esc> ` key to clear suggestions while preserving its other functionality:
46
54
47
55
``` lua
48
56
-- Clear copilot suggestion with Esc if visible, otherwise preserve default Esc behavior
49
57
vim .keymap .set (" n" , " <esc>" , function ()
50
- if not require (' copilot-lsp.nes' ).clear () then
58
+ if not require (" copilot-lsp.nes" ).clear () then
51
59
-- fallback to other functionality
52
60
end
53
61
end , { desc = " Clear Copilot suggestion or fallback" })
54
62
```
55
63
56
64
## Default Configuration
57
65
58
-
59
66
### NES (Next Edit Suggestion) Smart Clearing
67
+
60
68
You don’t need to configure anything, but you can customize the defaults:
61
69
` move_count_threshold ` is the most important. It controls how many cursor moves happen before suggestions are cleared. Higher = slower to clear.
62
70
@@ -68,7 +76,6 @@ require('copilot-lsp').setup({
68
76
})
69
77
```
70
78
71
-
72
79
### Blink Integration
73
80
74
81
``` lua
0 commit comments