aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc_src/bind.txt4
-rw-r--r--doc_src/index.hdr.in4
-rw-r--r--share/functions/fish_vi_key_bindings.fish32
-rw-r--r--src/input_common.cpp13
-rw-r--r--tests/bind.expect122
-rw-r--r--tests/bind.expect.out21
6 files changed, 111 insertions, 85 deletions
diff --git a/doc_src/bind.txt b/doc_src/bind.txt
index 77fb607a..3485f49b 100644
--- a/doc_src/bind.txt
+++ b/doc_src/bind.txt
@@ -135,8 +135,8 @@ Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line.
\subsection special-case-escape Special Case: The escape Character
-Since the escape key (or character) plays two distinct roles it poses a special challenge for fish. In its first role it stands by itself. In Vi mode, for example, escape is used to switch from insert to normal mode. In its second role escape is used as a <a href="https://en.wikipedia.org/wiki/Meta_key">"meta" key</a> where it is only the beginning of some longer character sequence. Coming back to the Vi mode example, sometimes fish is expected to realize that the escape key should be regarded as a meta key, meaning that the escape character is part of a multi-char sequence. Function keys (e.g., F1, F2, etc...) and arrow keys are common cases of multi-char sequences that begin with the escape character. Custom bindings can also be defined that begin with an escape character. Obviously, fish is not supposed to exit insert mode when the escape is part of a longer character sequence.
+Since the escape key (or character) plays two distinct roles it poses a special challenge for fish. In its first role it stands by itself. In Vi mode, for example, escape is used to switch from insert to normal (aka command) mode. In its second role escape is used as a <a href="https://en.wikipedia.org/wiki/Meta_key">"meta" key</a> where it is only the beginning of some longer character sequence. Coming back to the Vi mode example, sometimes fish is expected to realize that the escape key should be regarded as a meta key, meaning that the escape character is part of a multi-char sequence. Function keys (e.g., F1, F2, etc...) and arrow keys are common cases of multi-char sequences that begin with the escape character. Custom bindings can also be defined that begin with an escape character. Obviously, fish is not supposed to exit insert mode when the escape is part of a longer character sequence.
-To be able distinguish between these two roles fish has to wait after it sees an escape character. In this waiting period any additional key presses make the escape key behave as a meta key. Otherwise, it remains simply an escape key press. The waiting period is set to 500 milliseconds (0.5 seconds) by default. This is the Gnu readline library default escape timeout. It can be configured by setting the `fish_escape_delay_ms` variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session.
+To be able distinguish between these two roles fish has to wait after it sees an escape character. In this waiting period any additional key presses make the escape key behave as a meta key. Otherwise, it remains an isolated escape key press. The waiting period is set to 300 milliseconds (0.3 seconds) in the default key bindings and 10 milliseconds in the vi key bindings. It can be configured by setting the `fish_escape_delay_ms` variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session.
Note: fish versions up thru 2.2.0 used a default of 10 ms and provided no way to configure it. That effectively made it impossible to use escape as a meta key.
diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in
index b9e3f8fc..5eb92423 100644
--- a/doc_src/index.hdr.in
+++ b/doc_src/index.hdr.in
@@ -759,9 +759,7 @@ The user can change the settings of `fish` by changing the values of certain var
- `fish_greeting`, the greeting message printed on startup.
-- `fish_escape_delay_ms` to override the default timeout of 500 ms after
- seeing an escape character before giving up on matching a key binding. See
- the documentation for the <a hread='bind.html#special-case-escape'>bind</a> builtin.
+- `fish_escape_delay_ms` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the <a href='bind.html#special-case-escape'>bind</a> builtin command. This delay facilitates using escape as a meta key.
- `BROWSER`, the user's preferred web browser. If this variable is set, fish will use the specified browser instead of the system default browser to display the fish documentation.
diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish
index 98f2ca12..a1496b80 100644
--- a/share/functions/fish_vi_key_bindings.fish
+++ b/share/functions/fish_vi_key_bindings.fish
@@ -1,29 +1,29 @@
function fish_vi_key_bindings --description 'vi-like key bindings for fish'
- bind --erase --all
+ # The default escape timeout is 300ms. But for users of Vi bindings that can
+ # be slightly annoying when trying to switch to Vi "normal" mode. Too,
+ # vi-mode users are unlikely to use escape-as-meta. So set a much shorter
+ # timeout in this case.
+ set -q fish_escape_delay_ms; or set -g fish_escape_delay_ms 10
+
set -l init_mode insert
if set -q argv[1]
set init_mode $argv[1]
end
- # Inherit default key bindings
- # Do this first so vi-bindings win over default
+ # Inherit default key bindings.
+ # Do this first so vi-bindings win over default.
+ bind --erase --all
fish_default_key_bindings -M insert
fish_default_key_bindings -M default
- # Add a way to get out of insert mode
+ # Add a way to switch from insert to normal (command) mode.
bind -M insert -m default \cc force-repaint
bind -M insert -m default \e backward-char force-repaint
- ##
- ## command mode
- ##
-
- bind :q exit
-
#
- # normal (default) mode
+ # normal (command) mode
#
-
+ bind :q exit
bind \cd exit
bind \cc 'commandline ""'
bind h backward-char
@@ -128,9 +128,9 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
bind -m insert cge backward-kill-word force-repaint
bind -m insert cgE backward-kill-bigword force-repaint
- bind '~' capitalize-word
- bind gu downcase-word
- bind gU upcase-word
+ bind '~' capitalize-word
+ bind gu downcase-word
+ bind gU upcase-word
bind J end-of-line delete-char
bind K 'man (commandline -t) ^/dev/null; or echo -n \a'
@@ -172,7 +172,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
#
# Lowercase r, enters replace-one mode
#
-
bind -m replace-one r force-repaint
bind -M replace-one -m default '' delete-char self-insert backward-char force-repaint
bind -M replace-one -m default \e cancel force-repaint
@@ -180,7 +179,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish'
#
# visual mode
#
-
bind -M visual \e\[C forward-char
bind -M visual \e\[D backward-char
bind -M visual -k right forward-char
diff --git a/src/input_common.cpp b/src/input_common.cpp
index 291a37a7..ebe95fce 100644
--- a/src/input_common.cpp
+++ b/src/input_common.cpp
@@ -28,15 +28,10 @@ Implementation file for the low level input library
#include "env.h"
#include "iothread.h"
-/**
- Time in milliseconds to wait for another byte to be available for
- reading after \\x1b is read before assuming that escape key was
- pressed, and not an escape sequence.
-
- This is the value used by the readline library. It can be overridden by
- setting the fish_escape_delay_ms variable.
-*/
-#define WAIT_ON_ESCAPE_DEFAULT 500
+// Time in milliseconds to wait for another byte to be available for reading
+// after \x1b is read before assuming that escape key was pressed, and not an
+// escape sequence.
+#define WAIT_ON_ESCAPE_DEFAULT 300
static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;
/** Characters that have been read and returned by the sequence matching code */
diff --git a/tests/bind.expect b/tests/bind.expect
index f8caa166..6b5278ee 100644
--- a/tests/bind.expect
+++ b/tests/bind.expect
@@ -2,94 +2,128 @@
spawn $fish
expect_prompt
-# Test switching key bindings to vi mode. This should leave the mode in the
-# appropriate state (i.e., insert mode). These initial tests assume the
-# default escape timeout of 500ms is in effect.
+# Fish should start in default-mode (i.e., emacs) bindings. The default escape
+# timeout is 300ms.
+# Verify the emacs transpose word (\et) behavior using various delays,
+# including none, after the escape character.
+
+# Start by testing with no delay. This should transpose the words.
+send "echo abc def"
+send "\033t\r"
+expect_prompt -re {\r\ndef abc\r\n} {
+ puts "emacs transpose words, default timeout: no delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: no delay"
+}
+
+# Now test with a delay > 0 and < the escape timeout. This should transpose
+# the words.
+send "echo ghi jkl"
+send "\033"
+sleep 0.200
+send "t\r"
+expect_prompt -re {\r\njkl ghi\r\n} {
+ puts "emacs transpose words, default timeout: short delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: short delay"
+}
+
+# Now test with a delay > the escape timeout. The transposition should not
+# occur and the "t" should become part of the text that is echoed.
+send "echo mno pqr"
+send "\033"
+sleep 0.400
+send "t\r"
+expect_prompt -re {\r\nmno pqrt\r\n} {
+ puts "emacs transpose words, default timeout: long delay"
+} unmatched {
+ puts stderr "emacs transpose words fail, default timeout: long delay"
+}
+
+# Test vi key bindings.
+# This should leave vi mode in the insert state.
send "set -g fish_key_bindings fish_vi_key_bindings\r"
expect_prompt
+# These vi tests assume the fish_vi_key_bindings default escape timeout of
+# 10ms is in effect; not the 300ms timeout for the default-mode.
+#
# This test is only present to make the Travis-CI framework succeed
-# consistently. It's not clear why the following tests succeed without this
+# consistently. It's not clear why the subsequent tests succeed without this
# test when executed on a local machine but not in the Travis-CI framework.
send "echo success: default escape timeout\r"
expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
- puts "prime vi mode: default escape timeout"
+ puts "prime vi mode, default timeout"
} unmatched {
- puts stderr "prime vi mode fail: default escape timeout"
+ puts stderr "prime vi mode, default timeout"
}
send "echo fail: default escape timeout"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
-sleep 0.550
+sleep 0.020
send "ddi"
send "echo success: default escape timeout\r"
expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
- puts "vi replace line: default escape timeout"
+ puts "vi replace line, default timeout: long delay"
} unmatched {
- puts stderr "vi replace line fail: default escape timeout"
+ puts stderr "vi replace line, default timeout: long delay"
}
# Verify that a human can transpose words using \et (which is an emacs default
-# binding but should be valid while in vi insert mode).
+# binding but should be valid while in vi insert or normal mode).
send "echo abc def"
send "\033"
-# Fish should still be in vi insert mode after this delay to simulate a slow
-# typist.
-sleep 0.400
+sleep 0.005
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
- puts "vi transpose words: default escape timeout"
+ puts "vi transpose words, default timeout: short delay"
} unmatched {
- puts stderr "vi transpose words fail: default escape timeout"
+ puts stderr "vi transpose words, default timeout: short delay"
}
# Test replacing a single character.
send "echo TEXT"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
-sleep 0.550
+sleep 0.020
send "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
- puts "vi mode replace: default escape timeout"
-} -nounmatched -re {\r\nfail} {
- puts stderr "vi mode replace fail: default escape timeout"
+ puts "vi mode replace char, default timeout: long delay"
} unmatched {
- puts stderr "couldn't find expected output 'TAXT': default escape timeout"
+ puts stderr "vi mode replace char, default timeout: long delay"
}
-# Verify that changing the escape timeout has an effect. The vi key bindings
-# should still be in effect.
+# Verify that changing the escape timeout has an effect.
send "set -g fish_escape_delay_ms 100\r"
expect_prompt
-send "echo fail: shortened escape timeout"
+send "echo fail: lengthened escape timeout"
send "\033"
sleep 0.150
send "ddi"
-send "echo success: shortened escape timeout\r"
-expect_prompt -re {\r\nsuccess: shortened escape timeout\r\n} {
- puts "vi replace line: shortened escape timeout"
-} -nounmatched -re {\r\nfail} {
- puts stderr "vi replace line fail: shortened escape timeout"
+send "echo success: lengthened escape timeout\r"
+expect_prompt -re {\r\nsuccess: lengthened escape timeout\r\n} {
+ puts "vi replace line, 100ms timeout: long delay"
} unmatched {
- puts stderr "couldn't find expected output: replace_line, shortened escape timeout"
+ puts stderr "vi replace line, 100ms timeout: long delay"
}
# Verify that we don't switch to vi normal mode if we don't wait long enough
-# after sending escape. The vi key bindings should still be in effect.
+# after sending escape.
send "echo fail: no normal mode"
send "\033"
sleep 0.050
send "ddi"
send "inserted\r"
expect_prompt -re {\r\nfail: no normal modediinserted\r\n} {
- puts "vi normal mode: shortened escape timeout"
+ puts "vi replace line, 100ms timeout: short delay"
} unmatched {
- puts stderr "couldn't find expected output: no normal mode"
+ puts stderr "vi replace line, 100ms timeout: short delay"
}
# Switch back to regular (emacs mode) key bindings.
+# The custom escape timeout of 100ms set earlier should still be in effect.
send "set -g fish_key_bindings fish_default_key_bindings\r"
expect_prompt
@@ -98,36 +132,34 @@ expect_prompt
# Start by testing with no delay. This should transpose the words.
send "echo abc def"
-send "\033t\r"
+send "\033"
+send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
- puts "emacs transpose words: no escape delay"
+ puts "emacs transpose words, 100ms timeout: no delay"
} unmatched {
- puts stderr "emacs transpose words fail: no escape delay"
+ puts stderr "emacs transpose words fail, 100ms timeout: no delay"
}
-# Now test with a delay > 0 and < the escape timeout. This should transpose
-# the words.
-send "set -g fish_escape_delay_ms 100\r"
-expect_prompt
+# Same test as above but with a slight delay less than the escape timeout.
send "echo ghi jkl"
send "\033"
-sleep 0.050
+sleep 0.080
send "t\r"
expect_prompt -re {\r\njkl ghi\r\n} {
- puts "emacs transpose words: short escape delay"
+ puts "emacs transpose words, 100ms timeout: short delay"
} unmatched {
- puts stderr "emacs transpose words fail: short escape delay"
+ puts stderr "emacs transpose words fail, 100ms timeout: short delay"
}
# Now test with a delay > the escape timeout. The transposition should not
# occur and the "t" should become part of the text that is echoed.
send "echo mno pqr"
send "\033"
-sleep 0.150
+sleep 0.120
send "t\r"
expect_prompt -re {\r\nmno pqrt\r\n} {
- puts "emacs transpose words: long escape delay"
+ puts "emacs transpose words, 100ms timeout: long delay"
} unmatched {
- puts stderr "emacs transpose words fail: long escape delay"
+ puts stderr "emacs transpose words fail, 100ms timeout: long delay"
}
diff --git a/tests/bind.expect.out b/tests/bind.expect.out
index 2bb2dfe0..07902427 100644
--- a/tests/bind.expect.out
+++ b/tests/bind.expect.out
@@ -1,9 +1,12 @@
-prime vi mode: default escape timeout
-vi replace line: default escape timeout
-vi transpose words: default escape timeout
-vi mode replace: default escape timeout
-vi replace line: shortened escape timeout
-vi normal mode: shortened escape timeout
-emacs transpose words: no escape delay
-emacs transpose words: short escape delay
-emacs transpose words: long escape delay
+emacs transpose words, default timeout: no delay
+emacs transpose words, default timeout: short delay
+emacs transpose words, default timeout: long delay
+prime vi mode, default timeout
+vi replace line, default timeout: long delay
+vi transpose words, default timeout: short delay
+vi mode replace char, default timeout: long delay
+vi replace line, 100ms timeout: long delay
+vi replace line, 100ms timeout: short delay
+emacs transpose words, 100ms timeout: no delay
+emacs transpose words, 100ms timeout: short delay
+emacs transpose words, 100ms timeout: long delay