shift+enter keybinding not working
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+jworks as expected and inserts a newline.
Steps to Reproduce
- Open OpenCode.
- Focus on an input field.
- Press
shift+enterto try inserting a newline. - 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:
- When a key event occurs, the editor first checks if
msg.Text != ""(line 126)- If there's text in the message, it directly passes the message to the textarea's Update method (line 128)
ctrl+jis interpreted by the terminal as a newline character (\n), so msg.Text contains "\n"- 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.Textforshift+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+enteris 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:
- 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)- If a command matches, it gets executed via
commands.ExecuteCommandsMsg(matches)(line 310)- The InputNewlineCommand is configured with keybindings for "shift+enter" and "ctrl+j" (line 299 in command.go)
The problem is that when
shift+enteris pressed:
- It matches the
InputNewlineCommand- The command gets executed
- But there's likely no handler for InputNewlineCommand that actually calls the editor's
Newline()methodLet me check where commands are actually executed: qwen/qwen3-coder:free (09:00 PM)
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
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).
I face the same issue on mac built-in terminal and vscode.
@wanjuntham some terminals/multiplexers don't pass this through right, you can use ctrl+j in those cases, or you can remap the keybind
@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.
yes definitely annoying, kinda depends on your emulator tho, in ghostty and zed shift+enter works fine (many others too)
In alacritty, you just need to add the following to map shift+enter to \n.
[keyboard]
bindings = [ { key = "Return", mods = "Shift", chars = "\n" } ]
I have noticed that when I am using tmux in ghostty terminal on my mac, the shift enter does not work in opencode.
Same here in vscode. Solved by remapping submit, then enter inputs a new line
{
"keybinds": {
"input_submit": "alt+enter",
},
}
I actually have this issue in ghostty on Linux, but not when running another other TUI application I have built within ghostty
Very new to this tried Shift + Ender on termius and it acted as a submit.
I still cannot get shift+enter works in Warp terminal (ctrl+j works), quite frustrating 😂
Ps. shift+enter works on iTerm2
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
shift+enter used to work in ghostty with macos, and it no longer does. I use nushell, if that helps.
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.
shift+enter used to work in ghostty with macos, and it no longer does. I use nushell, if that helps.
facing the same problem!
@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
Yes, that fixed it. I do not remember adding that line :|
Apparently they added it to fix shift+enter at their end. It would be nice if one setting worked for both OC and CC.
@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.
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?
.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 if you named the file .opencode.json it wont get picked up you need to drop the prefix period
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")
gotcha I think vscode may still be capturing it unless the same problem occurs in a normal terminal outside vscode
@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\rthis 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?
we could probably adjust opencode to be able to handle it in addition to default case
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\rWhen 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.
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?
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)?