xonecas.io
7415
Va

vim-ai-complete / commit 07e2c5a

feat: don't auto set keybinds

xonecas2026-09-10 07e2c5ad926ce7c13583ce9ddf93815894f7eed5 parent 188d644

3 files changed

README.md+19−14
@@ -14,10 +14,7 @@ Add a plugin spec like this:
1414 -- ~/.config/nvim/lua/plugins/ai-complete.lua
1515 return {
1616 "sacenox/vim-ai-complete",
17- cmd = { "Ai" },
18- keys = {
19- { "<leader>a", function() require("ai_complete").complete_at_cursor() end, desc = "AI completion at cursor" },
20- },
17+ cmd = { "Ai", "AiComplete" },
2118 }
2219 ```
2320
@@ -26,21 +23,16 @@ For local development, use `dir` instead:
2623 ```lua
2724 return {
2825 dir = "~/src/vim-ai-complete",
29- cmd = { "Ai" },
30- keys = {
31- { "<leader>a", function() require("ai_complete").complete_at_cursor() end, desc = "AI completion at cursor" },
32- },
26+ cmd = { "Ai", "AiComplete" },
3327 }
3428 ```
3529
36-The `keys` entry also loads the plugin when you press `<leader>a`; omit it if that key is already used in your configuration.
37-
38-Note: when lazy-loading with `cmd = { "Ai" }`, the lowercase `:ai` abbreviation is only available after the plugin has loaded. Use `:Ai` to trigger loading, or define the abbreviation in `init`:
30+Note: when lazy-loading with `cmd = { "Ai", "AiComplete" }`, the lowercase `:ai` abbreviation is only available after the plugin has loaded. Use `:Ai` to trigger loading, or define the abbreviation in `init`:
3931
4032 ```lua
4133 return {
4234 "sacenox/vim-ai-complete",
43- cmd = { "Ai" },
35+ cmd = { "Ai", "AiComplete" },
4436 init = function()
4537 vim.cmd([[cabbrev ai Ai]])
4638 end,
@@ -58,6 +50,8 @@ git clone https://github.com/sacenox/vim-ai-complete.git
5850
5951 ## Usage
6052
53+### Replace visual selection
54+
6155 1. Select text in Visual mode.
6256 2. Run `:Ai <prompt>`.
6357 3. The selected text is replaced when generation succeeds.
@@ -68,9 +62,20 @@ Characterwise, linewise, and blockwise selections are supported. If generation f
6862
6963 ### Completion at the cursor
7064
71-Press `<leader>a` in Normal mode to insert a completion at the cursor, before the current character, without selecting text or entering a prompt. The agent receives the current buffer (including unsaved changes) and cursor position, and decides what to insert and whether to read additional context. Generation is blocking, just like `:Ai`.
65+Run `:AiComplete` to insert a completion at the cursor, before the current character, without selecting text or entering a prompt. The agent receives the current buffer (including unsaved changes) and cursor position, and decides what to insert and whether to read additional context. Generation is blocking, just like `:Ai`.
66+
67+The insertion is a single undoable edit: press `u` to discard it. Failed generation leaves the buffer unchanged.
68+
69+### Optional key mappings
70+
71+The plugin does not bind keys automatically. For example, add these mappings to your Neovim configuration to use `<leader>a` for completion in Normal mode and the prompt window in Visual mode:
72+
73+```lua
74+vim.keymap.set("n", "<leader>a", "<cmd>AiComplete<CR>", { desc = "AI completion at cursor" })
75+vim.keymap.set("x", "<leader>a", ":Ai<CR>", { desc = "AI replace selection" })
76+```
7277
73-The insertion is a single undoable edit: press `u` to discard it. Failed generation leaves the buffer unchanged. The default mapping is only installed if it does not conflict with an existing Normal-mode mapping.
78+The Visual-mode mapping uses `:` to preserve the selected range. Both mappings also work with the command-based lazy-loading examples above.
7479
7580 ## LLM command
7681
TODO.md+0−4
@@ -1,9 +1,5 @@
11 # TODO
22
3-## Suggest next _few_ lines?
4-
5-Either on idle cursor, or as an explicit command from the user, generate a suggestion from the code surrounding the current cursor position. Show it as a suggestion (italic maybe) with a vim command to accept.
6-
73 ## Look into asynchronous generation
84
95 Blocking the UI is a shortcut that ensures the buffer does not change and lets us easily insert the LLM output without collisions or conflicts by using Neovim's `gv` command.
plugin/ai_complete.lua+3−8
@@ -11,11 +11,6 @@ end, {
1111 range = true,
1212 })
1313
14-if vim.fn.mapcheck('<leader>a', 'n') == '' then
15- vim.keymap.set('n', '<leader>a', function()
16- require('ai_complete').complete_at_cursor()
17- end, { silent = true, desc = 'AI completion at cursor' })
18-end
19-
20--- User commands must start uppercase; support :ai as an abbreviation.
21-vim.cmd([[cabbrev ai Ai]])
14+vim.api.nvim_create_user_command('AiComplete', function()
15+ require('ai_complete').complete_at_cursor()
16+end, { desc = 'AI completion at cursor' })