如何在Bash阅读行中绑定"Enter键"? [英] How to bind the 'Enter key' in Bash readline?

查看:84
本文介绍了如何在Bash阅读行中绑定"Enter键"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我昨天学会了如何使用绑定.

So I learned how to use bind yesterday.

通过在终端中键入一个 Ctrl + v 后跟一个键,我得到了代表该键的原始字符.例如: Ctrl + v 后跟 Esc 返回^[.

By typing Ctrl+v followed by a key in the terminal, I get a raw character that represents the key. For example: Ctrl+v followed by Esc returns ^[.

我的问题是,如何绑定输入密钥". Enter键返回^M,但是当我键入命令

My question is, how can I bind the "enter key". The Enter Key returns ^M but when I type the command

bind '"\e^M":"foobar"'

按Enter键不会导致在我的终端中键入foobar.

pressing the enter key does not result in foobar being typed in my terminal.

推荐答案

bind '"\e^M":"foobar"'

绑定Escape-Enter,而不是Enter.你只想要

binds Escape-Enter, not Enter. You just want

bind '"^M":"foobar"'

^M必须是实际的控制字符,而不是^M.

^M must be the actual control character, not ^ and M. A little easier to type is

bind '"\C-M":"foobar"'

这篇关于如何在Bash阅读行中绑定"Enter键"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆