-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Escape as meta #1356
Comments
I'm was hoping someone else would chime in, so I wouldn't have to admit that I don't understand this at all :) Can you please give a concrete example or steps to reproduce? What is something you type, what do you hope to see, what do you see instead? |
@ridiculousfish start fish, write a word, then press |
Oh, I understand what you wanted to say on IRC before. Well, yes, there is a special feature that analyzes the timing to let you bind Escape button, but this shows it's probably more trouble than it's worth. Perhaps it could be disabled if there is no binding for Escape button? |
This feature does not work for me: However, from default binding: try again with a binary instead of a builtin: |
See also: #153 |
@Debilski Can you develop a bit more? I tried with or without tmux on Terminal.app as well and it does not work any better than iTerm2. |
Basically, what I do is starting a tmux session (which defaults to having bash as a shell, as I’m still in the process of switching) and then run fish inside that. Then, I can press Still, I’d also rather have this functionality in plain fish without having to fire up tmux. |
I see, I tried with an empty tmux configuration and indeed it works. However, it should be working without tmux and hopefully with my configuration :p I'll investigate which configuration exactly breaks this. In the meantime, if you are curious, here is my tmux conf: https://github.com/creack/dotfiles/blob/master/dot.tmux.conf |
It’s |
Thanks. It indeed work. However, this is still an issue for people not using tmux. |
Any official news on this? |
I'm new to fish. Very annoying that ESC does not work. Is this not important? |
any update on this? I just discovered fish, which looks really great, but without ESC as META, there is so much we can't do on mac! Is there something that I can do to help to find what is going wrong? |
Sorry I forgot to say this is with fish master branch on Mac OS X 10.10.3. I can reproduce the behavior with and without I've tried a bit to look at what is going on. I've found the
and with
The patch:
|
I was giving a shot to fish (and really liked it), and encountered the same show-stopper. Do we have an idea of where the problem is, and how big of a fix it is? |
I just tried |
@creack: Nope, this is not solved. There's probably something terminal-specific about it - I can't get it to work on konsole, urxvt and xterm. |
Yeah, I tried Terminal.app and iTerm2 on El Capitan with the latest brew and a port build on freebsd. I threw tmux 2.0 into the mix too, then my hands in the air because it didn't work like I wanted. |
@yannk It may be some tmux configuration issue. With tmux 2.0 and Terminal.app on El Capitan it works for me. Without tmux: No luck for me. But ESC will immediately delete a line when in history mode (eg. after pressing the up arrow a couple of times). Once I add characters to that line ESC resorts to doing nothing. |
$ bind \e
bind \e cancel
It's more general, I assure you. |
I think I am joining this request to support
* I tried these both with
Personally, I prefer |
There is a real problem. But identifying that problem and a solution has been hindered by a lot of confusing statements and bad conclusions. Let's start with the subject line of this issue "Support Escape as meta". You cannot use the [esc] key as a meta key. At least not without reconfiguring your terminal emulator to treat it as such which would be a pretty stupid thing to do. A meta key has to be held down while pressing a second key in order to modify the meaning of the second key. You cannot use the [esc] key in that fashion. You can configure your terminal emulator (and many are configured this way by default) to cause the [alt], [apple], or [windows] key (which are meta keys) to cause the next key pressed to send its normal character sequence preceded by an \e (i.e., \c[, aka the escape character). So [alt-a] would transmit the sequence \ea. Another behavior that was frequently seen in the not too distant past is for the meta key to cause the character(s) sent by the modified key to have its high-bit set. For example, [alt-a] would result in \xE1 being sent (the value for lowercase "a" with bit 7 set). That, however, is less common these days now that UTF-8 encoding is in widespread use. The reason that tmux seems to make a difference is that it alters the timing of the characters that pass through it. That's because tmux itself has to recognize multi-character sequences. You absolutely do not need to run tmux inside the Mac OS X standard Terminal.app to get the desired behavior. I can use tmux to produce the desired behavior inside iTerm2. But it is highly timing sensitive. If I wait too long after pressing [esc] before pressing the next character tmux does not bundle the characters tightly in the time domain and it fails to have a beneficial effect. On the other hand if I do type [esc] [some char] in quick succession then tmux forwards the two characters to fish with an even shorter interval between the chars. If you configure iTerm2 to treat the left and right [alt] keys as a "+Esc" modifier that will cause iTerm2 to treat use of the [alt] key as requiring the sequence emitted by the modified key to be prepended by an \e character. If you do that you should find that works reliably (I did) at least if communicating with a local fish shell rather than one reached via ssh. It's pretty obvious that fish is using a too short timeout after seeing an escape character (and possibly any other character) before deciding that no other relevant character is going to be received in its multi-char detection FSM (finite state machine). |
And I see that input_common.cpp has these lines:
Ten milliseconds in an interactive shell is far too short. This should be an order of magnitude (i.e., 100 ms or 1/10th of a second) longer. To be determined is what other shells like bash use for this timeout. |
It's an emacs-ism. Emacs was invented on a Space-cadet keyboard, which had quite a few modifier keys, including meta. Nowadays meta is usually replaced by alt, but emacs retains the terminology. It also (by default - mine doesn't) reads escape as it if were meta, which means when emacs says to press "M-x", you can either hold down alt and press x or press escape then x. So in emacs-speak, escape is effectively meta (by default, but then again there isn't much in emacs that you can't change). (All this means that the old joke about "emacs" standing for "Escape Meta Alt Control Shift" is kinda pointless as the first three are the same thing)
I'm not sure this would be a great thing to do given we also have a vi-mode, where you want escape to immediately change to normal mode. |
Couldn't the time interval be set in run-time, according to the current mode? This old evidence suggests that vim uses a 25ms window: |
A 25 ms window is way too short, @oranja. You cannot reliably press [esc] + some other key within that window. Also, that blog post does not show that Vim uses a 25 ms window. Only that when checking whether input is available on one of several file descriptors it waits at most 25 ms before doing other work. That is not the same thing as vim assuming a bare escape is present if 25 ms has gone by since an escape was read. The author jumped to a hasty conclusion. I checked the readline source code and it uses a 500 ms default timeout for this purpose. From readline.c:
It is configurable via the
At normal human (i.e., non X-men) speeds a delay of 100 ms is immediate, @faho. Even 500 ms will be unnoticed by most people and is thus immediate for all intents and purposes. The default timeout should be much larger and I propose following readline's lead and setting it to 500 ms. The only question is whether it should be customizable via something like the ESCDELAY env var recognized by the curses library and/or parsing $HOME/.inputrc for relevant values like keyseq-timeout. I'm mildly opposed to either since it's not clear this really needs to be configurable and we should minimize our reliance on idioms set by other projects. P.S., I built a custom fish with WAIT_ON_ESCAPE set to 500 and the bindings reported by others above work reliably in emacs mode. A couple of them (e.g., |
I'd like everyone who has commented on this issue to cherrypick the trivial change in 814cb51 and report on their experience. |
Thanks @krader1961 The only catch is that I'm not using vi-mode, so I can't speak in the name of those who do. |
Works great with 814cb51! |
FWIW, I personally prefer a timeout of 300 ms. But that's mostly because fish currently has a somewhat weird behavior of inheriting the default bindings while in vi-mode. Which means, for example, that \ed is a valid sequence in vi-mode. However, that short of an escape timeout could be a problem for some people unable to press consecutive keys that fast (as opposed to relying on real meta keys that convert the keystrokes to an escape sequence). |
After several more days using a fish built with my change I think the escape timeout needs to be configurable. I find a 500 ms timeout is just a tad too long (as in annoying) when wanting to switch from vi insert to normal mode and I can reliably press escape plus some other char in ~200 ms. But there will be people who will need that long of a delay to reliably press escape followed by another character in a key binding. So I'd like to leave the default at 500 ms but allow the user to set a fish_escape_delay_ms var to the number of milliseconds they prefer be used (obviously with reasonable limits such as not less than 10 ms and not more than 1000 ms). Any objections? |
Perhaps setting the normal mode default to ~500ms and vi-mode default to ~250ms would please all newcomers? I believe something like this should give the great-out-of-the-box experience that Fish aims for. Together with an option for customization (fish_escape_delay_ms), it's probably as good as anyone could ask for. |
@oranja I don't think there is enough value in a mode specific default to justify the added complexity. This basically boils down to fast versus slow typists. That is, if we want to support escape as a "meta key" then we have to allow a significant delay between the escape key and the next key stroke. The optimal delay depends on the individual. Some people can consistently press [escape] with very little delay before pressing some other key (e.g., less than 300 ms). Other people need at least a third of a second. This wouldn't be as much of an issue if it weren't for the need to support "vi" mode. |
Oh my. |
Tried to figure out why escape had a very noticeable delay. There it is. So I suppose I have to custom compile to remove the delay? |
Aha, found this for anyone else that comes across this issue: https://fishshell.com/docs/current/commands.html#special-case-escape
|
Note that we ultimately set the default to 300 ms:
If you set it too low (e.g., less than 10 ms) you may find it hard to reliably use any key which sends a sequence starting with escape (which is most of them). |
I am using fish 2.1.0 and Escape is not considered meta.
This is really annoying, especially on OSX. You could configure iTerm to make 'alt' behave like meta, however, and I quote fish website,
Bash, zsh, emacs, and many more support out of the box Escape as meta, which allow a proper usage without having to temper with the terminal configuration.
I understand why Fish is not POSIX, however, I don't see any argument why this should not be supported.
After discussing on IRC, it seems that it IS supported. However, it does not work on OSX with terminal, iTerm2 or with direct TTY within virtualbox.
Is it a bug? Is it expected? If yes, how could I work around it to make it work?
And please, do not tell me to configure my iTerm. I want to use
Escape
, notAlt
.The text was updated successfully, but these errors were encountered: