Feature Request: Support customizable keybinding for inserting newlines (e.g., Shift+Enter) #984
shuizhongyueming
started this conversation in
Ideas
Replies: 1 comment
-
|
mac 用户完全没有被考虑。 mac users are not considered at all. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
功能请求:支持自定义插入换行的快捷键 / Support customizable keybinding for inserting newlines
问题描述 / Problem Description
目前 kimi-cli 中插入换行的快捷键固定为
Ctrl-J和Alt-Enter。然而:Alt-Enter在某些终端(如 VS Code 内置终端、部分版本的 iTerm2)可能无法正常工作Shift-Enter技术调研 / Technical Research
我调研了 opencode 的实现方式,以下是技术细节:
1. opencode 的默认配置
2. 键盘协议支持
opencode 使用 kitty keyboard protocol 和 xterm modifyOtherKeys 来检测带修饰键的 Enter:
\x1b[13;2u\x1b[27;2;13~\x1b[27;5;13~\x1b[27;6;13~3. 终端兼容性
opencode 文档指出,部分终端需要手动配置才能发送修饰键信息:
Windows Terminal 配置示例:
支持的终端:
建议的实现方案 / Proposed Solutions
方案 A:配置文件支持(推荐)
添加
keybindings配置项,允许用户自定义快捷键:实现要点:
Config类添加keybindings字段CustomPromptSession读取配置并应用键绑定Shift-Enter等需要特殊处理的键,使用底层的键盘监听(类似现有的keyboard.py)优点:
方案 B:添加 Shift-Enter 作为默认选项
在默认键绑定中增加对 Shift-Enter 的支持(如果终端支持)。
实现要点:
keyboard.py识别 kitty/xterm 的扩展键盘序列prompt.py中处理SHIFT_ENTER事件优点:
缺点:
可能的实现代码参考 / Implementation Reference
基于我的调研,以下是可能的实现思路:
讨论点 / Discussion Points
是否值得支持 Shift-Enter?
配置格式的设计
c-j,escape enter)?ctrl+j,alt+enter)?是否只实现配置支持,还是同时添加 Shift-Enter 作为默认选项?
文档和错误处理
环境信息 / Environment
我很乐意根据讨论结果来实现这个功能,并提交 PR。期待维护团队的反馈!
Feature request: Support customizable keybinding for inserting newlines / Support customizable keybinding for inserting newlines
Problem Description / Problem Description
Currently, the shortcut keys for inserting newlines in kimi-cli are fixed to
Ctrl-JandAlt-Enter. However:Alt-Entermay not work properly in some terminals (such as VS Code built-in terminal, some versions of iTerm2)Shift-EnterTechnical Research / Technical Research
I investigated the implementation of opencode, and the following are the technical details:
1. Default configuration of opencode
2. Keyboard protocol support
opencode uses kitty keyboard protocol and xterm modifyOtherKeys to detect Enter with modified keys:
\x1b[13;2u\x1b[27;2;13~\x1b[27;5;13~\x1b[27;6;13~3. Terminal compatibility
The opencode documentation points out that some terminals require manual configuration to send modifier key information:
Windows Terminal configuration example:
Supported Terminals:
Suggested Implementation Solution / Proposed Solutions
Solution A: Configuration file support (recommended)
Add
keybindingsconfiguration item to allow users to customize shortcut keys:Implementation points:
Configclass to add thekeybindingsfieldCustomPromptSessionto read the configuration and apply key bindingsShift-Enter, use the underlying keyboard monitor (similar to the existingkeyboard.py)Advantages:
Option B: Add Shift-Enter as default option
Add support for Shift-Enter in default keybindings (if supported by the terminal).
Implementation points:
keyboard.pyto recognize extended keyboard sequences of kitty/xtermSHIFT_ENTERevent inprompt.pyAdvantages:
Disadvantages:
Possible implementation code reference / Implementation Reference
Based on my research, the following are possible implementation ideas:
Discussion Points / Discussion Points
**Is it worth supporting Shift-Enter? **
Design of configuration format
c-j,escape enter)?ctrl+j,alt+enter)?**Is only configuration support implemented, or is Shift-Enter also added as a default option? **
Documentation and Error Handling
Environment Information / Environment
I'd be happy to implement this feature based on the discussion and submit a PR. Looking forward to feedback from the maintenance team!
Beta Was this translation helpful? Give feedback.
All reactions