aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-10-07 10:22:52 +0800
committerGitHub <noreply@github.com>2024-10-07 02:22:52 +0000
commitbf868e76e14447c7fed0c9a778f2e0ec4cb5011a (patch)
treefe2660b65cb1f39053d516be1f26ff0cf3d0d938
parent40ec3d7bc0e255a1159f4b2c27c6dcea5d13ca3d (diff)
downloadrneovim-bf868e76e14447c7fed0c9a778f2e0ec4cb5011a.tar.gz
rneovim-bf868e76e14447c7fed0c9a778f2e0ec4cb5011a.tar.bz2
rneovim-bf868e76e14447c7fed0c9a778f2e0ec4cb5011a.zip
vim-patch:9.1.0762: 'cedit', 'termwinkey' and 'wildchar' may not be parsed correctly (#30704)
Problem: 'cedit', 'termwinkey' and 'wildchar' may not be parsed correctly Solution: improve string_to_key() function in option.c (Milly) - Problem: `^@` raises an error. Solution: Store as `<Nul>`. - Problem: `<t_xx` does not raise an error. Solution: Raise an error if closing `>` is missing. - Problem: Single `<` or `^` raises an error. It is inconvenient for users. Solution: They are stored as a single character. closes: vim/vim#15811 https://github.com/vim/vim/commit/a9c6f90918d0012d1b8c8c5c1dccb77407f553fb Co-authored-by: Milly <milly.ca@gmail.com>
-rw-r--r--runtime/doc/options.txt7
-rw-r--r--runtime/lua/vim/_meta/options.lua7
-rw-r--r--src/nvim/option.c16
-rw-r--r--src/nvim/options.lua7
4 files changed, 29 insertions, 8 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 2c2d67c3f0..4248560851 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -7076,7 +7076,12 @@ A jump table for the options with a short description can be found at |Q_op|.
Some keys will not work, such as CTRL-C, <CR> and Enter.
<Esc> can be used, but hitting it twice in a row will still exit
command-line as a failsafe measure.
- Although 'wc' is a number option, you can set it to a special key: >vim
+ Although 'wc' is a number option, it can be specified as a number, a
+ single character, a |key-notation| (e.g. <Up>, <C-F>) or a letter
+ preceded with a caret (e.g. `^F` is CTRL-F): >vim
+ :set wc=27
+ :set wc=X
+ :set wc=^I
set wc=<Tab>
<
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
index 27384dbccc..2bff777899 100644
--- a/runtime/lua/vim/_meta/options.lua
+++ b/runtime/lua/vim/_meta/options.lua
@@ -7699,9 +7699,14 @@ vim.go.ww = vim.go.whichwrap
--- Some keys will not work, such as CTRL-C, <CR> and Enter.
--- <Esc> can be used, but hitting it twice in a row will still exit
--- command-line as a failsafe measure.
---- Although 'wc' is a number option, you can set it to a special key:
+--- Although 'wc' is a number option, it can be specified as a number, a
+--- single character, a `key-notation` (e.g. <Up>, <C-F>) or a letter
+--- preceded with a caret (e.g. `^F` is CTRL-F):
---
--- ```vim
+--- :set wc=27
+--- :set wc=X
+--- :set wc=^I
--- set wc=<Tab>
--- ```
---
diff --git a/src/nvim/option.c b/src/nvim/option.c
index aa6f330dfc..f54da54a4b 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1525,7 +1525,9 @@ static int find_key_len(const char *arg_arg, size_t len, bool has_lt)
// Don't use get_special_key_code() for t_xx, we don't want it to call
// add_termcap_entry().
if (len >= 4 && arg[0] == 't' && arg[1] == '_') {
- key = TERMCAP2KEY((uint8_t)arg[2], (uint8_t)arg[3]);
+ if (!has_lt || arg[4] == '>') {
+ key = TERMCAP2KEY((uint8_t)arg[2], (uint8_t)arg[3]);
+ }
} else if (has_lt) {
arg--; // put arg at the '<'
int modifiers = 0;
@@ -1539,14 +1541,18 @@ static int find_key_len(const char *arg_arg, size_t len, bool has_lt)
}
/// Convert a key name or string into a key value.
-/// Used for 'wildchar' and 'cedit' options.
+/// Used for 'cedit', 'wildchar' and 'wildcharm' options.
int string_to_key(char *arg)
{
- if (*arg == '<') {
+ if (*arg == '<' && arg[1]) {
return find_key_len(arg + 1, strlen(arg), true);
}
- if (*arg == '^') {
- return CTRL_CHR((uint8_t)arg[1]);
+ if (*arg == '^' && arg[1]) {
+ int key = CTRL_CHR((uint8_t)arg[1]);
+ if (key == 0) { // ^@ is <Nul>
+ key = K_ZERO;
+ }
+ return key;
}
return (uint8_t)(*arg);
}
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 0d3f7154af..db04de1e3a 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -9620,7 +9620,12 @@ return {
Some keys will not work, such as CTRL-C, <CR> and Enter.
<Esc> can be used, but hitting it twice in a row will still exit
command-line as a failsafe measure.
- Although 'wc' is a number option, you can set it to a special key: >vim
+ Although 'wc' is a number option, it can be specified as a number, a
+ single character, a |key-notation| (e.g. <Up>, <C-F>) or a letter
+ preceded with a caret (e.g. `^F` is CTRL-F): >vim
+ :set wc=27
+ :set wc=X
+ :set wc=^I
set wc=<Tab>
<
]=],