DEV Community

loach
loach

Posted on Originally published at zenn.dev

Using Ctrl+Enter to Submit in OpenCode and Enter for New Lines

Another OpenCode behavior I wanted to change was message submission.

By default, pressing Enter submits the current prompt. If you are used to chat tools where Enter inserts a new line and Ctrl + Enter sends, this makes accidental submissions easy.

My preferred setup is:

  • Enter: insert a new line
  • Ctrl + Enter: submit the prompt

OpenCode configuration

Edit your OpenCode configuration file and update the keybindings:

{
  "keybinds": {
    "app_exit": "ctrl+d,<leader>q",
    "input_submit": "ctrl+return",
    "input_newline": "shift+return,return,alt+return,ctrl+j"
  }
}
Enter fullscreen mode Exit fullscreen mode

This tells OpenCode to treat normal Enter-style keys as new lines and reserve Ctrl + Enter for submission.

The terminal may need configuration too

There is one important detail: some terminals do not send a distinct key sequence for Ctrl + Enter by default.

In that case, OpenCode cannot distinguish it from plain Enter.

For Windows Terminal, you can define a custom sequence:

"actions": [
  {
    "command": {
      "action": "sendInput",
      "input": "\u001b[13;5u"
    },
    "id": "User.sendInput.CtrlEnterCustom"
  }
]
Enter fullscreen mode Exit fullscreen mode

Then bind Ctrl + Enter to that action in the terminal settings.

The exact terminal configuration can vary, but the principle is the same: the terminal must send a distinguishable sequence before OpenCode can bind it separately.

Why this improves the workflow

Long prompts often contain code blocks, lists, and multiple paragraphs.

Making Enter safe for editing removes the pressure to finish the whole prompt on one line and reduces accidental sends.

It also makes OpenCode behave more like many chat and editor-oriented interfaces.

Closing thoughts

Keybindings are a small detail, but AI coding tools are used interactively for long periods. Small interaction problems become surprisingly expensive when repeated all day.

For me, separating newline and submit made OpenCode much more comfortable to use.

Top comments (0)