opencode icon indicating copy to clipboard operation
opencode copied to clipboard

shift+enter keybinding not working

Open bluenex opened this issue 5 months ago • 86 comments

I noticed that the shift+enter keybinding, which is supposed to insert a newline in the input field, doesn’t seem to work. However, the alternative keybinding ctrl+j works fine for the same action.

Expected Behavior

When I press shift+enter, it should insert a newline in the input field.

Observed Behavior

  • Pressing shift+enter
    • Does nothing when the input is blank
    • Send the message when the input is not blank
  • On the other hand, ctrl+j works as expected and inserts a newline.

Steps to Reproduce

  1. Open OpenCode.
  2. Focus on an input field.
  3. Press shift+enter to try inserting a newline.
  4. Notice that nothing happens.

Environment

  • Platform: macOS M2 (version 14.6.1)
  • Terminal: tested on Terminal and Warp
  • Version: tested on dev branch

Analysis by Qwen3 Coder

That's the key! Looking at the editor code, I can see what's happening:

  1. When a key event occurs, the editor first checks if msg.Text != "" (line 126)
  2. If there's text in the message, it directly passes the message to the textarea's Update method (line 128)
  3. ctrl+j is interpreted by the terminal as a newline character (\n), so msg.Text contains "\n"
  4. This gets passed directly to the textarea, which inserts it as a newline

However, shift+enter is not interpreted as text by the terminal - it's sent as a special key event. Since there's no msg.Text for shift+enter, the code doesn't take the early return path, and instead continues to process the key event through the rest of the switch statement.

The issue is that shift+enter is not being handled specifically in the editor's key processing logic. Let me look at where commands are actually executed: qwen/qwen3-coder:free (09:00 PM)

Now I understand the issue! Looking at the code flow:

  1. In the TUI's Update method, key events are first checked against commands using a.app.Commands.Matches(msg, a.app.IsLeaderSequence) (line 304 in tui.go)
  2. If a command matches, it gets executed via commands.ExecuteCommandsMsg(matches) (line 310)
  3. The InputNewlineCommand is configured with keybindings for "shift+enter" and "ctrl+j" (line 299 in command.go)

The problem is that when shift+enter is pressed:

  1. It matches the InputNewlineCommand
  2. The command gets executed
  3. But there's likely no handler for InputNewlineCommand that actually calls the editor's Newline() method

Let me check where commands are actually executed: qwen/qwen3-coder:free (09:00 PM)

bluenex avatar Aug 01 '25 14:08 bluenex

I’m going to close https://github.com/sst/opencode/issues/1941 but do want to note that this only happens in vscode for me. i dont have this issue when running in iterm or ghostty

the-vampiire avatar Aug 15 '25 20:08 the-vampiire

I’m going to close #1941 but do want to note that this only happens in vscode for me. i dont have this issue when running in iterm or ghostty

I have the issue on Fedora with ddterm. I know some teammates have the issue too, but idk which terminal (on linux distro too).

fmatsos avatar Aug 15 '25 21:08 fmatsos

I face the same issue on mac built-in terminal and vscode.

wanjuntham avatar Aug 16 '25 07:08 wanjuntham

@wanjuntham some terminals/multiplexers don't pass this through right, you can use ctrl+j in those cases, or you can remap the keybind

rekram1-node avatar Aug 16 '25 12:08 rekram1-node

@wanjuntham some terminals/multiplexers don't pass this through right, you can use ctrl+j in those cases, or you can remap the keybind

yes ctrl + j works, but I am already so used to shift + enter keybind for inserting a new line.

wanjuntham avatar Aug 16 '25 14:08 wanjuntham

yes definitely annoying, kinda depends on your emulator tho, in ghostty and zed shift+enter works fine (many others too)

rekram1-node avatar Aug 16 '25 14:08 rekram1-node

In alacritty, you just need to add the following to map shift+enter to \n.

[keyboard]
bindings = [ { key = "Return", mods = "Shift", chars = "\n" } ]

SMFloris avatar Aug 16 '25 20:08 SMFloris

I have noticed that when I am using tmux in ghostty terminal on my mac, the shift enter does not work in opencode.

hamza-m-masood avatar Aug 19 '25 21:08 hamza-m-masood

Same here in vscode. Solved by remapping submit, then enter inputs a new line

{
  "keybinds": {
    "input_submit": "alt+enter",
  },
}

hd-o avatar Aug 29 '25 01:08 hd-o

I actually have this issue in ghostty on Linux, but not when running another other TUI application I have built within ghostty

CSRessel avatar Sep 08 '25 16:09 CSRessel

Very new to this tried Shift + Ender on termius and it acted as a submit.

ahosker avatar Sep 11 '25 14:09 ahosker

I still cannot get shift+enter works in Warp terminal (ctrl+j works), quite frustrating 😂 Ps. shift+enter works on iTerm2

mrgoonie avatar Sep 14 '25 12:09 mrgoonie

Consider implementing a default configuration that works with vscode. ctrl + j is a default keybinding in vscode to toggle panel (e.g., terminal) visibility shift + enter doesn't work

joseph-hlucny avatar Sep 20 '25 13:09 joseph-hlucny

shift+enter used to work in ghostty with macos, and it no longer does. I use nushell, if that helps.

esafak avatar Sep 23 '25 02:09 esafak

Is there any config in opencode itself to remap these things? Shift+enter still doesn't work for me in opencode in cursor and vscode .

But shift+enter works just fine directly in terminals (ghostty, warp, wezterm,...) so I'm confident the issue is opencode.

Ctrl + J is not an option for me as it's already used for open/close IDE terminal.

Ideally, we just need simple support for changing the key binding in opencode. Claude code and Charm already support this and makes it so much easier to use what you are already familiar with.

codeagencybe avatar Sep 23 '25 12:09 codeagencybe

shift+enter used to work in ghostty with macos, and it no longer does. I use nushell, if that helps.

facing the same problem!

epicwhale avatar Sep 27 '25 08:09 epicwhale

@esafak @epicwhale along with anyone else turns out (most likely) claude code changes your ghostty settings (this is what I've been told at least)

Not sure if this will address for everyone but from what I have seen this is the problem that most people had

if you check your ghostty config there is most likely a line

keybind = shift+enter=text:\x1b\r

this breaks shift enter in opencode

rekram1-node avatar Sep 29 '25 20:09 rekram1-node

Yes, that fixed it. I do not remember adding that line :|

esafak avatar Sep 29 '25 20:09 esafak

Apparently they added it to fix shift+enter at their end. It would be nice if one setting worked for both OC and CC.

esafak avatar Sep 29 '25 21:09 esafak

@rekram1-node good catch! i have that too, removing it does make it work in opencode in ghostty, but now breaks it in CC, haha. Btw CC manipulates it in /terminal-setup command.

The VS Code terminal shift+enter not working still remains a mystery... as the CC ghostty config does not apply there.

epicwhale avatar Sep 29 '25 21:09 epicwhale

I have noticed that when I am using tmux in ghostty terminal on my mac, the shift enter does not work in opencode.

I had this in my config as well:

# Claude Code terminal integration
keybind = shift+enter=text:\x1b\r

When I remove this things work as expected.

But inside tmux it still dosn't work. Did you find a solution?

martinmose avatar Sep 30 '25 07:09 martinmose

.opencode.json

{
  "keybinds": {
    "input_submit": "ctrl+enter",
  },
}

in vscode doesn't work.

I've even gone into vscode keybind settings and wipe out anything that is "ctrl+enter".

nada.

airtonix avatar Oct 02 '25 00:10 airtonix

@airtonix if you named the file .opencode.json it wont get picked up you need to drop the prefix period

rekram1-node avatar Oct 02 '25 01:10 rekram1-node

yeah i might have mistyped that here in the comments, but regardless... it still doesn't work (i confirmed i used the right file name because restarting i see the updated help text under the input field say "blah blah blah ctrl+enter" where it normally says "blah blah blah... enter")

airtonix avatar Oct 02 '25 01:10 airtonix

gotcha I think vscode may still be capturing it unless the same problem occurs in a normal terminal outside vscode

rekram1-node avatar Oct 02 '25 02:10 rekram1-node

@esafak @epicwhale along with anyone else turns out (most likely) claude code changes your ghostty settings (this is what I've been told at least)

Not sure if this will address for everyone but from what I have seen this is the problem that most people had

if you check your ghostty config there is most likely a line

keybind = shift+enter=text:\x1b\r

this breaks shift enter in opencode

I use both Claude Code and opencode on a daily basis and removing this config in ghostty breaks shift+enter in Claude Code and keeping this line breaks shift+enter in opencode. Is there a solution to get shift+enter work the same in both Claude Code and opencode?

flexdinesh avatar Oct 08 '25 01:10 flexdinesh

we could probably adjust opencode to be able to handle it in addition to default case

rekram1-node avatar Oct 08 '25 01:10 rekram1-node

I have noticed that when I am using tmux in ghostty terminal on my mac, the shift enter does not work in opencode.

I had this in my config as well:

# Claude Code terminal integration
keybind = shift+enter=text:\x1b\r

When I remove this things work as expected.

But inside tmux it still dosn't work. Did you find a solution?

It’s because I’m a tmux noob… Adding set -s extended-keys on to my .tmux.conf fixed it for me.

martinmose avatar Oct 10 '25 07:10 martinmose

On Windows 11, Shift+Enter doesn’t work in Alacritty. (installed with npm) with this alacritty.toml configuration:

[keyboard] bindings = [ { key = "Enter", mods = "Shift", chars = "\n" }, ]

How can I fix this?

JSCOP avatar Oct 11 '25 02:10 JSCOP

Hm I'm not sure I will look into it... Does ctrl + j work as an alternative?

Does shift enter work for other terminal tools (for u)?

rekram1-node avatar Oct 11 '25 03:10 rekram1-node