Sign up ×

By default, when entering information at the command prompt in mutt, you can clear the prompt with Ctrlg, as described in the manual:

^G              n/a             abort

I have been trying to bind this function to Escape. Unfortunately, abort is not listed in the available functions, either in the manual, or in the source.

I have tried using this in my .muttrc:

bind editor <esc>       abort

but it throws an error:

Error in /home/jason/.mutt/muttrc, line 143: abort: no such function in map

I have tried using a different map, like (generic) and experimented with other fictitious functions, like clear, to no avail.

How would I bind Escape to clear the prompt line?

share|improve this question
Binding escape is not a good idea as the escape character (sent upon pressing escape) is also the prefix for escape sequences sent by all function keys like arrows, del, F1... –  Stéphane Chazelas Sep 11 '12 at 6:20
That's a good point that I had not considered. Testing it, Escape needs to be sent twice to send a literal ^[ so it may not be a showstopper (I don't use any binds that rely on it anyway). –  jasonwryan Sep 11 '12 at 6:58
Esc, Esc would send two ESC characters. You can also press Esc once and wait about one second (the default timeout waiting for the rest of an escape sequence). –  Stéphane Chazelas Sep 11 '12 at 9:19
Yes. First I have to work out how to bind it :) –  jasonwryan Sep 11 '12 at 9:20

3 Answers 3

up vote 4 down vote accepted

It's not possible with key bindings. Ctrl-G is hardcoded in mutt at a lower level than the macro or keybinding processing (see mutt_getch() in mutt's source code, at the core of all user input in mutt that returns an error upon ^G).

macro editor \e '^G'

wouldn't work either.

What you can do is configure your terminal to send ^G upon pressing Escape

With xterm:

xterm -xrm 'XTerm.VT100.translations: #override <KeyPress> Escape: string(0x7)'

If you're using screen, you can also do

screen -X bindkey $'\e' stuff $'\a'

before calling mutt and restore it afterwards (unfortunately, it doesn't seem you can have per screen window key bindings in screen). Also, it's going to be a problem if your editor for email messages is vi.

share|improve this answer
Upvoted: because it answers the question (ie., it's not possible). Could you please elaborate on the "hardcoded... at a lower level". And while the workaround is ingenious, it is not really practicable as I use Escape in a lot of other terminal programs--hence the desire to bind it here. –  jasonwryan Sep 11 '12 at 9:41
I've edited my answer with more details. I'm surprised you have Esc bound in other programs as it usually isn't in applications I know for the reason mentioned in comments above. –  Stéphane Chazelas Sep 11 '12 at 11:22
Thank you: that is helpful. –  jasonwryan Sep 11 '12 at 17:47

It seems like a really bad idea to me to bind escape to control+g also. I came here looking for a mutt solution, but since it seems there is none, I'll give an answer from what I'm doing for anyone who happens to stumble across this. It's not optimal but it won't affect any other programs:

macro editor \e "<enter><shell-escape>xdotool control+g<enter>"


macro editor \e "<enter><shell-escape>xsendkey Control+g<enter>"

Using something like xdotool or xsendkey to fake control+g works and doesn't mess up escape everywhere else. There's a visual delay for me for it to exit the line editor, but index bindings will work immediately and the visual delay will be gone as soon as you use an index binding. The first enter is necessary so that mutt won't just type out "...." and make that into a header or search term or something.

share|improve this answer

This solution is so bad that the author prefered to edit Mutt's source code to get rid of ^G

Warning: This solution seems incompatiple with OSX, Emacs and other aplications that use Ctrl+G

After my first day at Mutt, I was almost using ^G in Vim by mistake... Then I tried something that seems to work here, in i3 window manager and xfce-terminal.

Added this line to ~/.i3/config:

bindsym --release Escape exec --no-startup-id xvkbd -xsendevent -text "\[Escape]\[Control]\[g]"

Had to use "\[Escape]\[Control]\[g]" because only "\[Control]\[g]" made it stop working in Vim.

If you are not using i3, I think you can use xbindkeys to run xvkbd -xsendevent -text "\[Escape]\[Control]\[g]" when Esc is pressed.

It's not a beautiful solution... It can make your Esc key unusable in some programs, but at least here it seems ok.


I see now that the Ctrl+G part makes Vim shows position in file. Nothing too dramatic, for now.

This link seems to have a better solution, but for urxvt:

share|improve this answer

Your Answer


