Skip to content

feat(shell): support Shift+Enter for inserting newlines#2255

Open
donbeave wants to merge 1 commit into
MoonshotAI:mainfrom
donbeave:feat/shift-enter-newline
Open

feat(shell): support Shift+Enter for inserting newlines#2255
donbeave wants to merge 1 commit into
MoonshotAI:mainfrom
donbeave:feat/shift-enter-newline

Conversation

@donbeave
Copy link
Copy Markdown

@donbeave donbeave commented May 13, 2026

Related Issue

Closes #2254
Related: #2010, #2121, #1585, #1574

Description

This PR adds Shift+Enter as an alternative shortcut for inserting a newline in the interactive prompt, complementing the existing Ctrl-J and Alt-Enter bindings.

Why this matters

Shift+Enter has become the de-facto standard across modern chat UIs and CLI agents:

  • Claude CodeShift+Enter inserts newline
  • Codex CLIShift+Enter inserts newline
  • OpenCodeShift+Enter inserts newline
  • AmpShift+Enter inserts newline
  • ChatGPT, Discord, Slack, Cursor → all use Shift+Enter for newline

Kimi CLI's current Ctrl-J / Alt-Enter shortcuts work, but they break muscle memory for users coming from any of these platforms. This small UX friction is one of the most frequently requested features in the issue tracker (4+ open issues).

What changed

  1. Register xterm modifyOtherKeys ANSI sequences for Shift+Enter (\x1b[27;2;13~) and Alt+Enter (\x1b[27;3;13~). Alt+Enter is mapped to a private-use character (\ue000) so it can be bound independently of plain Enter, preserving its newline behavior during completions.
  2. Intercept plain Enter to distinguish Shift+Enter (insert \n) from plain Enter (submit message).
  3. Enable xterm modifyOtherKeys on session startup (\x1b[>4;1m) and disable it on exit (\x1b[>4;0m) so supporting terminals emit distinct sequences.
  4. Update bottom toolbar hint from ctrl-j: newline to shift-enter / ctrl-j: newline.
  5. Update English docs (docs/en/reference/keyboard.md, docs/en/guides/interaction.md).
  6. Update test assertions in tests/ui_and_conv/test_prompt_tips.py.
  7. Add ANSI sequence registration tests in tests/ui_and_conv/test_prompt_shift_enter.py.
  8. Add PTY e2e tests for Shift+Enter and Alt+Enter newline insertion.

Backward compatibility

  • Ctrl-J and Alt-Enter continue to work exactly as before.
  • No configuration changes required.
  • Terminals that do not support xterm modifyOtherKeys simply fall back to the existing behavior.

Test plan

  • make format passes
  • make check passes (pre-existing diagnostics unrelated to this change)
  • pytest tests/ui_and_conv/test_prompt_tips.py passes (60/60)
  • pytest tests/ui_and_conv/ passes (723/723)
  • pytest tests/e2e/test_shell_pty_e2e.py::test_shell_shift_enter_inserts_newline passes
  • pytest tests/e2e/test_shell_pty_e2e.py::test_shell_alt_enter_inserts_newline passes
  • Verified ctrl-j still inserts a newline in existing tests
  • Manual smoke test in iTerm2 (xterm modifyOtherKeys): Shift+Enter inserts newline, plain Enter submits, autocomplete with completion menu open still works

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread src/kimi_cli/ui/shell/prompt.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4643ce401

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kimi_cli/ui/shell/prompt.py Outdated
@donbeave donbeave force-pushed the feat/shift-enter-newline branch from b4643ce to d9d0daa Compare May 13, 2026 04:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9d0daa4c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kimi_cli/ui/shell/prompt.py Outdated
Comment thread src/kimi_cli/ui/shell/prompt.py
@donbeave donbeave force-pushed the feat/shift-enter-newline branch 4 times, most recently from fe7dd7b to 0181b2b Compare May 13, 2026 04:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0181b2badd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1547 to +1548
self._session.app.output.write_raw("\x1b[>4;1m")
self._session.app.output.flush()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve Alt-Enter newline after enabling modifyOtherKeys

Enabling xterm modifyOtherKeys here changes how modified Enter keys are encoded in supporting terminals, so Alt+Enter is no longer sent as escape + enter and the existing @_kb.add("escape", "enter") newline binding won’t fire. Because this patch only registers \x1b[27;2;13~ (Shift+Enter), users on terminals that honor \x1b[>4;1m will lose the previously supported Alt-Enter newline shortcut, which is a behavioral regression from prior releases and contradicts the updated docs/PR notes.

Useful? React with 👍 / 👎.

@donbeave donbeave force-pushed the feat/shift-enter-newline branch from 0181b2b to d1d24f2 Compare May 13, 2026 05:00
Add Shift+Enter as an alternative shortcut for inserting a newline in the
interactive prompt, alongside the existing Ctrl-J and Alt-Enter bindings.

This aligns Kimi CLI with the de-facto standard used by Claude Code,
Codex CLI, ChatGPT, Discord, Slack, and most modern chat UIs.

Changes:
- Register xterm modifyOtherKeys ANSI sequences for Shift+Enter and
  Alt+Enter, mapping Alt+Enter to a private-use character so it can be
  bound independently of the plain Enter key (preserving Alt+Enter
  newline behavior during completions).
- Intercept plain Enter to distinguish Shift+Enter (insert \n) from
  plain Enter (submit).
- Enable xterm modifyOtherKeys on session startup and disable it on
  exit so supporting terminals emit distinct sequences.
- Update bottom toolbar hint to "shift-enter / ctrl-j: newline".
- Update English documentation (keyboard.md, interaction.md).
- Update existing test assertions for toolbar tips.
- Add PTY e2e tests for Shift+Enter and Alt+Enter newline insertion.
- Add ANSI sequence registration tests.

Ctrl-J and Alt-Enter continue to work exactly as before.

Closes MoonshotAI#2254
Related: MoonshotAI#2010, MoonshotAI#2121, MoonshotAI#1585, MoonshotAI#1574

Signed-off-by: Alexey Zhokhov <alexey@zhokhov.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(shell): support Shift+Enter for inserting newlines

1 participant