Only map Copilot keys if plugin was found.
dblume

dblume commited on 2025-11-10 16:34:56
Showing 1 changed files, with 7 additions and 8 deletions.

... ...
@@ -54,13 +54,6 @@ inoremap <expr> <Tab> pumvisible() ? '<Down>' : '<Tab>'
54 54
 inoremap <expr> <S-Tab> pumvisible() ? '<Up>' : '<S-Tab>'
55 55
 inoremap <expr> <cr> pumvisible() ? '<C-y>' : '<cr>'
56 56
 
57
-" I don't have access to the Meta key on macOS with Microsoft Keyboard and Karabiner.
58
-" Copilot mappings from :help copilot
59
-imap <C-h> <Plug>(copilot-accept-line)
60
-imap <C-j> <Plug>(copilot-next)
61
-imap <C-k> <Plug>(copilot-previous)
62
-imap <C-l> <Plug>(copilot-accept-word)
63
-
64 57
 " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
65 58
 nnoremap <leader>v <C-w>v:bp<cr><C-w>l
66 59
 nnoremap <C-h> <C-w>h
... ...
@@ -539,7 +532,13 @@ lua << EOF
539 532
       -- https://github.com/CopilotC-Nvim/CopilotChat.nvim/issues/1062
540 533
       vim.keymap.set('i', '<S-Tab>', 'copilot#Accept("\\<S-Tab>")', { expr = true, replace_keycodes = false })
541 534
       vim.keymap.set({ 'n' }, '<leader>aa', chat.toggle, { desc = 'AI Toggle' })
542
-      break
535
+    elseif str:find("copilot") then
536
+      -- No access to the Meta key on macOS with Microsoft Keyboard and Karabiner.
537
+      -- So remap the Copilot suggestion keys to Ctrl+<h,j,k,l>. See :help copilot
538
+      vim.keymap.set('i', '<C-h>', '<Plug>(copilot-accept-line)')
539
+      vim.keymap.set('i', '<C-j>', '<Plug>(copilot-next)')
540
+      vim.keymap.set('i', '<C-k>', '<Plug>(copilot-previous)')
541
+      vim.keymap.set('i', '<C-l>', '<Plug>(copilot-accept-word)')
543 542
     end
544 543
   end
545 544
 
546 545