Skip to content

Missing readline ctrl+f (forward-char) / ctrl+b (backward-char) #4000

Closed

Description

@jdanbrown

Description

ctrl+f (forward-char) and ctrl+b (backward-char) are common keybindings from readline that cli tools typically support for line editing. Currently they do nothing in opencode, would be nice to add them.

OpenCode version

1.0.36

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macOS 15.5

Terminal

VS Code terminal

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 6, 2025
  2. github-actions commented on Nov 6, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • Ctrl-u not clearing input field #3647: Both issues are about missing or broken readline keybindings in OpenCode v1.0+ (opentui system). Issue Ctrl-u not clearing input field #3647 reports that most readline keybindings work except for ctrl-u and ctrl-d, while this issue reports missing ctrl+f and ctrl+b. These could potentially be addressed together as part of a comprehensive readline keybinding implementation.

    Feel free to ignore if none of these address your specific case.

  3. jdanbrown commented on Nov 6, 2025

    @jdanbrown
    ContributorAuthor

    Adding ctrl+f and ctrl+b (and ctrl+u) looks pretty straightforward, but would it be better if they went into opentui rather than opencode? I was sketching this out quickly with an llm to see how much work it would be, but along the way I couldn't find other basic line-editing keys like ctrl+k, ctrl+a, and ctrl+e defined in opencode, so that made me wonder if maybe these things should live in opentui instead.

    $ git diff
    diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
    index c977f731..0a80657e 100644
    --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
    +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
    @@ -566,6 +566,33 @@ export function Prompt(props: PromptProps) {
                       e.preventDefault()
                       return
                     }
    +                if (keybind.match("input_forward_char", e)) {
    +                  const cursorOffset = input.cursorOffset
    +                  if (cursorOffset < input.plainText.length) {
    +                    input.cursorOffset = cursorOffset + 1
    +                  }
    +                  e.preventDefault()
    +                  return
    +                }
    +                if (keybind.match("input_backward_char", e)) {
    +                  const cursorOffset = input.cursorOffset
    +                  if (cursorOffset > 0) {
    +                    input.cursorOffset = cursorOffset - 1
    +                  }
    +                  e.preventDefault()
    +                  return
    +                }
    +                if (keybind.match("input_kill_line_backward", e)) {
    +                  const cursorOffset = input.cursorOffset
    +                  if (cursorOffset > 0) {
    +                    const text = input.plainText
    +                    const newText = text.slice(cursorOffset)
    +                    input.setText(newText)
    +                    input.cursorOffset = 0
    +                  }
    +                  e.preventDefault()
    +                  return
    +                }
                     if (keybind.match("app_exit", e)) {
                       await exit()
                       return
    diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
    index c2ee63c6..3be2cfb4 100644
    --- a/packages/opencode/src/config/config.ts
    +++ b/packages/opencode/src/config/config.ts
    @@ -465,6 +465,11 @@ export namespace Config {
           agent_cycle_reverse: z.string().optional().default("shift+tab").describe("Previous agent"),
           input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
           input_forward_delete: z.string().optional().default("ctrl+d").describe("Forward delete"),
    +      input_kill_line_backward: z
    +        .string()
    +        .optional()
    +        .default("ctrl+u")
    +        .describe("Delete from cursor to beginning of line"),
           input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
           input_submit: z.string().optional().default("return").describe("Submit input"),
           input_newline: z
    @@ -472,6 +477,16 @@ export namespace Config {
             .optional()
             .default("shift+return,ctrl+j")
             .describe("Insert newline in input"),
    +      input_forward_char: z
    +        .string()
    +        .optional()
    +        .default("ctrl+f,right")
    +        .describe("Move cursor forward one character"),
    +      input_backward_char: z
    +        .string()
    +        .optional()
    +        .default("ctrl+b,left")
    +        .describe("Move cursor backward one character"),
           history_previous: z.string().optional().default("up").describe("Previous history item"),
           history_next: z.string().optional().default("down").describe("Next history item"),
           session_child_cycle: z
    
    $ git diff --stat
     packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx | 27 +++++++++++++++++++++++++++
     packages/opencode/src/config/config.ts                       | 15 +++++++++++++++
     2 files changed, 42 insertions(+)
  4. kommander commented on Nov 13, 2025

    @kommander
    Contributor

    This should work in the latest version?

  5. cwegener commented on Nov 13, 2025

    @cwegener

    Started working for me when I installed version 1.0.60 yesterday

  6. jdanbrown commented on Nov 18, 2025

    @jdanbrown
    ContributorAuthor

    Thanks! Confirmed working now as of 1.0.76 (or earlier).

  7. sim590 commented on Oct 11, 2026

    @sim590

    This is now broken. They added a new binding for ctrl-b in V2 and now readline's standard ctrl-b doesn't work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions