gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Shift+Enter - New line

Open aakash-shakya opened this issue 1 year ago • 19 comments

What happened?

When i try to go for next line and do Shift+Enter. Instead of new line, it sends message too.

What did you expect to happen?

expected to go for next line.

Client information

  • CLI Version: 0.1.7
  • Git Commit: 55cc809
  • Operating System: linux v20.17.0
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-flash
  • Memory Usage: 192.6 MB

Login information

logged in using google account

Anything else we need to know?

No response

aakash-shakya avatar Jun 30 '25 09:06 aakash-shakya

Hi aakash, Thank you for reporting and discussing the Shift+Enter new line issue.

Many users expect Shift+Enter to insert a new line in the Gemini CLI input prompt (like in chat apps). However, in many terminal environments, pressing Shift+Enter does not send a unique key event. In some cases, it sends the same event as Enter, or even a regular character (like 'c'), making it impossible for the CLI to distinguish between Shift+Enter and other keys.

Technical Limitation

  • Terminal emulators are responsible for sending key events to applications. Most do not send a unique escape sequence for Shift+Enter.
  • Node.js/Ink (the libraries powering the CLI) can only work with what the terminal sends. If Shift+Enter is not distinguishable from Enter or another key, there is no way for the CLI to handle it differently in code.
  • This is a well-known limitation in the terminal ecosystem and affects many CLI applications, not just Gemini CLI.

Workarounds

  • ctrl + enter
  • / + enter
  • Paste Multiline
  • Terminal Remapping (Advanced)

Conclusion

  • There is no robust, cross-platform, code-only solution for Shift+Enter in terminal CLIs due to terminal limitations.
  • We recommend using paste for multiline input, or terminal remapping for advanced users.
  • We will update the documentation to clarify this limitation and provide guidance for remapping.

If you have a terminal that supports custom key bindings, you can use the remapping workaround above. Otherwise, please use paste as a workaround for multiline input. Thank you for your understanding and contributions!

Let us know if you have further questions or suggestions.

ATHARVA262005 avatar Jun 30 '25 12:06 ATHARVA262005

@ATHARVA262005 but if I remember /help mentions Shift+Enter for new line, correct? This would need to be changed to ctrl + enter then.

deyil avatar Jun 30 '25 16:06 deyil

@deyil okay I will work on that and will raise a pr , thanks for sharing

ATHARVA262005 avatar Jun 30 '25 17:06 ATHARVA262005

CTRL-J or ALT-Enter for newline in Linux Gemini CLI (at least for me) personally i would prefer: enter = newline. ctrl-enter = submit.

nerdCopter avatar Jun 30 '25 19:06 nerdCopter

Using \ + Enter key

Image

wildcatDownstairs avatar Jul 01 '25 04:07 wildcatDownstairs

CTRL-J or ALT-Enter for newline in Linux Gemini CLI (at least for me).

It works for me too.

aakash-shakya avatar Jul 01 '25 08:07 aakash-shakya

@aakash-shakya This issue should already be solved can you send the screenshot after running /help command in the CLI it should show you the correct shortcut to enter new line.

For Linux Ctrl +J should work or Alt + Enter for certain distros like RHEL10 what linux distro are you using?

devpool007 avatar Jul 01 '25 10:07 devpool007

It shows Shift + Enter. @devpool007

Image

deyil avatar Jul 01 '25 10:07 deyil

Hi @deyil could you please share your system info and how are you running Gemini CLI? If your running by cloning the repo and building I recommend fetching latest changes.

devpool007 avatar Jul 01 '25 10:07 devpool007

@aakash-shakya This issue should already be solved can you send the screenshot after running /help command in the CLI it should show you the correct shortcut to enter new line.

For Linux Ctrl +J should work or Alt + Enter for certain distros like RHEL10 what linux distro are you using?

I just ran npx https://github.com/google-gemini/gemini-cli to check on latest code. And yes, it shows the Ctrl+J - New line (Alt+Enter works for certain linux distros)

Image

aakash-shakya avatar Jul 01 '25 11:07 aakash-shakya

@devpool007 I am on 0.1.7 version through npm

Image

deyil avatar Jul 01 '25 11:07 deyil

@devpool007 I am on 0.1.7 version through npm

Image

I think you would need to update your version you have an older one, I am on 0.1.8 currently

devpool007 avatar Jul 01 '25 11:07 devpool007

Today I updated it and it put me on 0.1.7

deyil avatar Jul 01 '25 12:07 deyil

@aakash-shakya I think since the

@aakash-shakya This issue should already be solved can you send the screenshot after running /help command in the CLI it should show you the correct shortcut to enter new line. For Linux Ctrl +J should work or Alt + Enter for certain distros like RHEL10 what linux distro are you using?

I just ran npx https://github.com/google-gemini/gemini-cli to check on latest code. And yes, it shows the Ctrl+J - New line (Alt+Enter works for certain linux distros)

Image

Hi, since this issue is already resolved, I think it's best to close it.

devpool007 avatar Jul 01 '25 15:07 devpool007

@aakash-shakya I think since the

@aakash-shakya This issue should already be solved can you send the screenshot after running /help command in the CLI it should show you the correct shortcut to enter new line. For Linux Ctrl +J should work or Alt + Enter for certain distros like RHEL10 what linux distro are you using?

I just ran npx https://github.com/google-gemini/gemini-cli to check on latest code. And yes, it shows the Ctrl+J - New line (Alt+Enter works for certain linux distros) Image

Hi, since this issue is already resolved, I think it's best to close it.

this issue is resolved, so I will close it now. Thanks everyone.

aakash-shakya avatar Jul 01 '25 15:07 aakash-shakya

@devpool007 I am on 0.1.7 version through npm Image

I think you would need to update your version you have an older one, I am on 0.1.8 currently

I want to clarify something as I made a typo in my last comment. Today that I updated the package through npm, it updated genimi cli to version 0.1.7 not 0.1.8. Also in released versions there is not a 0.1.8 version.

deyil avatar Jul 01 '25 17:07 deyil

@ATHARVA262005 If it's a fundamental Terminal limitation, why did Shift + Enter work for me with Claude Code out of the box? Clearly there is a way! It's possible my setup somehow enabled this (I use Warp).

tomarshall avatar Nov 18 '25 16:11 tomarshall

@ATHARVA262005 If it's a fundamental Terminal limitation, why did Shift + Enter work for me with Claude Code out of the box? Clearly there is a way! It's possible my setup somehow enabled this (I use Warp).

Thanks for the question — that’s a great point.

You're right that Claude Code in Warp handles Shift+Enter, and that can definitely make it seem like the CLI should support it universally. The key detail here is:

🔹 Warp is not a traditional terminal

Warp is a GPU-accelerated, fully custom terminal environment with its own key-handling layer. Because of that, Warp intercepts certain key combinations (including Shift+Enter) and sends distinct escape sequences to applications — escape sequences that traditional terminals (gnome-terminal, xterm, Alacritty, iTerm2, etc.) simply don't send.

🔹 Why this works in Claude Code but not Gemini CLI

Claude Code (inside Warp) receives a unique key event for Shift+Enter because Warp emits one.

In most standard terminals, Shift+Enter does not emit any unique sequence — it’s identical to Enter or sometimes not forwarded at all.

The Gemini CLI (built on Node.js + Ink) can only react to what the terminal sends. When Shift+Enter isn’t distinguishable, the CLI can’t treat it as a newline.

🔹 So the limitation isn’t the CLI itself

It’s the terminal emulator’s ability (or not) to send a different sequence for Shift+Enter.

Warp makes this possible. Most terminals don’t.

ATHARVA262005 avatar Nov 19 '25 15:11 ATHARVA262005

I use ctrl+j for tmux navigation so I couldn't use that. Luckily Ghostty (my choice of terminal) can capture shift+enter and send alt+enter. I know that this is terminal specific but I'm leaving it as a workaround (generated by Gemini)


Yes, it is possible to simulate Alt+Enter (which gemini-cli recognizes as a newline) using Shift+Enter in Ghostty.

Because standard terminals often send the exact same code for Enter and Shift+Enter, gemini-cli cannot distinguish between them by default. However, Alt+Enter typically sends an Escape character (\x1b) followed by a Carriage Return (\r). You can map Shift+Enter to send this specific sequence in your Ghostty configuration.

How to Configure Ghostty

Add the following line to your Ghostty configuration file (usually located at ~/.config/ghostty/config):

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

Explanation

  • shift+enter: The key combination you want to press.
  • text:: Tells Ghostty to send a specific string of text/characters.
  • \x1b: The hexadecimal code for the Escape key (which acts as the Alt modifier in most terminals).
  • \r: The escape sequence for Carriage Return (the standard Enter key signal).

After saving the file, you may need to reload your Ghostty configuration (usually Ctrl+Shift+,) or restart the terminal for the changes to take effect.

mauriciopoppe avatar Jan 19 '26 18:01 mauriciopoppe