Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ programs.nixvim = {

`opencode.nvim` replaces placeholders in prompts with the corresponding context:

| Placeholder | Context |
| -------------- | ------------------------------------------------------------- |
| `@this` | Operator range or visual selection if any, else cursor position |
| `@buffer` | Current buffer |
| `@buffers` | Open buffers |
| `@visible` | Visible text |
| `@diagnostics` | Current buffer diagnostics |
| `@quickfix` | Quickfix list |
| `@diff` | Git diff |
| `@marks` | Global marks |
| `@grapple` | [grapple.nvim](https://github.com/cbochs/grapple.nvim) tags |
| Placeholder | Context |
| -------------- | --------------------------------------------------------------- |
| `@this` | Operator range or visual selection if any, else cursor position |
| `@buffer` | Current buffer |
| `@buffers` | Open buffers |
| `@visible` | Visible text |
| `@diagnostics` | Current buffer diagnostics |
| `@quickfix` | Quickfix list |
| `@diff` | Git diff |
| `@marks` | Global marks |
| `@grapple` | [grapple.nvim](https://github.com/cbochs/grapple.nvim) tags |

### Prompts

Expand Down Expand Up @@ -244,6 +244,19 @@ vim.g.opencode_opts = {

Please submit PRs adding new providers! 🙂

#### Keymaps

`opencode.nvim` sets these buffer-local keymaps in provider terminals for Neovim-like message navigation:

| Keymap | Command | Description |
| ------- | ------------------------ | ---------------------------- |
| `<C-u>` | `session.half.page.up` | Scroll up half page |
| `<C-d>` | `session.half.page.down` | Scroll down half page |
| `<Esc>` | `session.interrupt` | Interrup (same as esc press) |
| `gg` | `session.first` | Go to first message |
| `G` | `session.last` | Go to last message |


## 🚀 Usage

### ✍️ Ask — `require("opencode").ask()`
Expand Down
2 changes: 1 addition & 1 deletion lua/opencode/provider/snacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Snacks.health()
return "`snacks.nvim` is not available.", {
"Install `snacks.nvim` and enable `snacks.terminal.`",
}
elseif not snacks.config.get("terminal", {}).enabled then
elseif not snacks and snacks.config.get("terminal", {}).enabled then
return "`snacks.terminal` is not enabled.",
{
"Enable `snacks.terminal` in your `snacks.nvim` configuration.",
Expand Down
1 change: 1 addition & 0 deletions lua/opencode/provider/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Terminal:start()

self.bufnr = vim.api.nvim_create_buf(true, false)
self.winid = vim.api.nvim_open_win(self.bufnr, true, self.opts)
vim.api.nvim_set_option_value("filetype", "opencode_terminal", { buf = self.bufnr })

-- Redraw terminal buffer on initial render.
-- Fixes empty columns on the right side.
Expand Down
27 changes: 27 additions & 0 deletions plugin/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Apply buffer-local keymaps to `opencode_terminal` filetype buffers.
vim.api.nvim_create_autocmd("FileType", {
pattern = "opencode_terminal",
callback = function(ev)
local opts = { buffer = ev.buf }

vim.keymap.set("n", "<C-u>", function()
require("opencode.api.command").command("session.half.page.up")
end, vim.tbl_extend("force", opts, { desc = "Scroll up half page" }))

vim.keymap.set("n", "<C-d>", function()
require("opencode.api.command").command("session.half.page.down")
end, vim.tbl_extend("force", opts, { desc = "Scroll down half page" }))

vim.keymap.set("n", "gg", function()
require("opencode.api.command").command("session.first")
end, vim.tbl_extend("force", opts, { desc = "Go to first message" }))

vim.keymap.set("n", "G", function()
require("opencode.api.command").command("session.last")
end, vim.tbl_extend("force", opts, { desc = "Go to last message" }))

vim.keymap.set("n", "<Esc>", function()
require("opencode.api.command").command("session.interrupt")
end, vim.tbl_extend("force", opts, { desc = "Interrupt current session (esc)" }))
end,
})