From dc3d0435c06a1f5c08ebc028e9b344f520761beb Mon Sep 17 00:00:00 2001 From: yimhuang Date: Wed, 11 Mar 2026 17:21:11 +0800 Subject: [PATCH] Add opencode to nvim --- init.lua | 2 +- lua/custom/plugins/opencode.lua | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 lua/custom/plugins/opencode.lua diff --git a/init.lua b/init.lua index cacc5b7b..92088787 100644 --- a/init.lua +++ b/init.lua @@ -940,7 +940,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/custom/plugins/opencode.lua b/lua/custom/plugins/opencode.lua new file mode 100644 index 00000000..68b7fd4d --- /dev/null +++ b/lua/custom/plugins/opencode.lua @@ -0,0 +1,50 @@ +return { + "nickjvandyke/opencode.nvim", + version = "*", -- Latest stable release + dependencies = { + { + -- `snacks.nvim` integration is recommended, but optional + ---@module "snacks" <- Loads `snacks.nvim` types for configuration intellisense + "folke/snacks.nvim", + optional = true, + opts = { + input = {}, -- Enhances `ask()` + picker = { -- Enhances `select()` + actions = { + opencode_send = function(...) return require("opencode").snacks_picker_send(...) end, + }, + win = { + input = { + keys = { + [""] = { "opencode_send", mode = { "n", "i" } }, + }, + }, + }, + }, + }, + }, + }, + config = function() + ---@type opencode.Opts + vim.g.opencode_opts = { + -- Your configuration, if any; goto definition on the type or field for details + } + + vim.o.autoread = true -- Required for `opts.events.reload` + + -- Recommended/example keymaps + vim.keymap.set({ "n", "x" }, "", function() require("opencode").ask("@this: ", { submit = true }) end, { desc = "Ask opencode…" }) + vim.keymap.set({ "n", "x" }, "", function() require("opencode").select() end, { desc = "Execute opencode action…" }) + vim.keymap.set({ "n", "t" }, "", function() require("opencode").toggle() end, { desc = "Toggle opencode" }) + + vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Add range to opencode", expr = true }) + vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Add line to opencode", expr = true }) + + vim.keymap.set("n", "", function() require("opencode").command("session.half.page.up") end, { desc = "Scroll opencode up" }) + vim.keymap.set("n", "", function() require("opencode").command("session.half.page.down") end, { desc = "Scroll opencode down" }) + + -- You may want these if you use the opinionated `` and `` keymaps above — otherwise consider `o…` (and remove terminal mode from the `toggle` keymap) + vim.keymap.set("n", "+", "", { desc = "Increment under cursor", noremap = true }) + vim.keymap.set("n", "-", "", { desc = "Decrement under cursor", noremap = true }) + end, +}