diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e8913f773..8138ff502 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Scripting improvements Interactive improvements ------------------------ +- Vi mode key bindings now support counts for movement and deletion commands (e.g. `d3w` or `3l`), via a new operator mode (:issue:`2192`). New or improved bindings ------------------------ diff --git a/doc_src/cmds/fish_mode_prompt.rst b/doc_src/cmds/fish_mode_prompt.rst index 18f2bcc62..d16b89f66 100644 --- a/doc_src/cmds/fish_mode_prompt.rst +++ b/doc_src/cmds/fish_mode_prompt.rst @@ -20,7 +20,7 @@ Description The ``fish_mode_prompt`` function outputs the mode indicator for use in vi mode. -The default ``fish_mode_prompt`` function will output indicators about the current vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. The ``$fish_bind_mode variable`` can be used to determine the current mode. It will be one of ``default``, ``insert``, ``replace_one``, ``replace``, or ``visual``. +The default ``fish_mode_prompt`` function will output indicators about the current vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. The ``$fish_bind_mode variable`` can be used to determine the current mode. It will be one of ``default``, ``insert``, ``replace_one``, ``replace``, ``visual``, or ``operator``. You can also define an empty ``fish_mode_prompt`` function to remove the vi mode indicators:: @@ -55,6 +55,9 @@ Example case visual set_color --bold brmagenta echo 'V' + case operator + set_color --bold cyan + echo 'N' case '*' set_color --bold red echo '?' diff --git a/localization/po/de.po b/localization/po/de.po index ec758ae68..2e28e7b6b 100644 --- a/localization/po/de.po +++ b/localization/po/de.po @@ -2383,6 +2383,9 @@ msgstr "" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "Abkürzung hinzufügen" @@ -3301,6 +3304,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/en.po b/localization/po/en.po index f28dd004f..634582696 100644 --- a/localization/po/en.po +++ b/localization/po/en.po @@ -2381,6 +2381,9 @@ msgstr "(Used together with -o) Do not overwrite but append" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "" @@ -3299,6 +3302,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/fr.po b/localization/po/fr.po index ad80c9551..623d540cf 100644 --- a/localization/po/fr.po +++ b/localization/po/fr.po @@ -2512,6 +2512,9 @@ msgstr "(Utilisé avec -o) Ne pas écraser le fichier, y concaténer les résult msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "Ajouter une abréviation" @@ -3430,6 +3433,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/pl.po b/localization/po/pl.po index 5158de641..f7208446e 100644 --- a/localization/po/pl.po +++ b/localization/po/pl.po @@ -2377,6 +2377,9 @@ msgstr "" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "" @@ -3295,6 +3298,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/pt_BR.po b/localization/po/pt_BR.po index cf13ba361..e06cb9586 100644 --- a/localization/po/pt_BR.po +++ b/localization/po/pt_BR.po @@ -2382,6 +2382,9 @@ msgstr "(Used together with -o) Do not overwrite but append" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "" @@ -3300,6 +3303,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/sv.po b/localization/po/sv.po index 368cc6e54..2381b124e 100644 --- a/localization/po/sv.po +++ b/localization/po/sv.po @@ -2378,6 +2378,9 @@ msgstr "(Används tillsamans med -o) Skriv inte över utan lägg till" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "" @@ -3296,6 +3299,9 @@ msgstr "" msgid "Reverse the order" msgstr "" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "" diff --git a/localization/po/zh_CN.po b/localization/po/zh_CN.po index fd88f8bc4..50fc94918 100644 --- a/localization/po/zh_CN.po +++ b/localization/po/zh_CN.po @@ -2410,6 +2410,9 @@ msgstr "(与 -o 一起使用) 不覆写但追加" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "执行 `breakpoint` 时使用的正确提示符" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "添加缩写" @@ -3328,6 +3331,9 @@ msgstr "反色文本" msgid "Reverse the order" msgstr "倒转顺序" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "作为登录 shell 运行" diff --git a/localization/po/zh_TW.po b/localization/po/zh_TW.po index 88f67df09..855b59948 100644 --- a/localization/po/zh_TW.po +++ b/localization/po/zh_TW.po @@ -2385,6 +2385,9 @@ msgstr "(和 -o 同時使用)加到結尾而不覆寫" msgid "A right prompt to be used when `breakpoint` is executed" msgstr "breakpoint 執行時要使用的右側提示" +msgid "Accumulate a digit for the next command" +msgstr "" + msgid "Add abbreviation" msgstr "新增縮寫" @@ -3303,6 +3306,9 @@ msgstr "反轉文字顏色" msgid "Reverse the order" msgstr "反轉順序" +msgid "Run a command $__fish_vi_count times" +msgstr "" + msgid "Run as a login shell" msgstr "作為登入 shell 執行" diff --git a/share/functions/fish_default_mode_prompt.fish b/share/functions/fish_default_mode_prompt.fish index f8ae0ccaa..e607dc0c1 100644 --- a/share/functions/fish_default_mode_prompt.fish +++ b/share/functions/fish_default_mode_prompt.fish @@ -18,6 +18,9 @@ function fish_default_mode_prompt --description "Display vi prompt mode" case visual set_color --bold magenta echo '[V]' + case operator + set_color --bold cyan + echo '[N]' end set_color normal echo -n ' ' diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 96b7d2591..d1749ca3f 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -6,6 +6,117 @@ function fish_vi_inc fish_vi_inc_dec inc end +function fish_vi_arg_digit --description 'Accumulate a digit for the next command' + set -g __fish_vi_count "$__fish_vi_count$argv[1]" +end + +function fish_vi_run_count --description 'Run a command $__fish_vi_count times' + set -l count (__fish_vi_consume_count __fish_vi_count) + + for i in (seq $count) + # Check if the first argument is a defined shell function (like fish_vi_move_end_word) + if functions -q -- $argv[1] + $argv + else + commandline -f $argv + end + end +end + +function fish_vi_start_operator + set -g __fish_vi_operator $argv[1] + set -g __fish_vi_start_count (__fish_vi_consume_count __fish_vi_count) + set fish_bind_mode operator + commandline -f repaint-mode +end + +function fish_vi_operator_cancel + set -g __fish_vi_operator + set -g __fish_vi_start_count + set -g __fish_vi_count + set fish_bind_mode default + commandline -f repaint-mode +end + +function __fish_vi_consume_count -a varname + set -l effective_count $$varname + if test -z "$effective_count" + set effective_count 1 + end + set -g $varname + echo $effective_count +end + +function fish_vi_exec_motion + argparse linewise -- $argv + or return + + set -l motion $argv + set -l total (math (__fish_vi_consume_count __fish_vi_start_count) \* (__fish_vi_consume_count __fish_vi_count)) + + set fish_bind_mode default + + if set -ql _flag_linewise + switch $__fish_vi_operator + case delete + for i in (seq $total) + commandline -f kill-whole-line + end + case change + for i in (seq $total) + commandline -f kill-inner-line + end + set fish_bind_mode insert + case yank + for i in (seq $total) + commandline -f kill-whole-line yank + end + case swap-case + for i in (seq $total) + commandline -f beginning-of-line begin-selection down-line togglecase-selection end-selection + end + end + commandline -f repaint-mode + else + switch $__fish_vi_operator + case delete + commandline -f begin-selection + for i in (seq $total) + commandline -f $motion + end + commandline -f kill-selection end-selection repaint-mode + case change + commandline -f begin-selection + for i in (seq $total) + commandline -f $motion + end + commandline -f kill-selection end-selection repaint-mode + # Switch to insert mode + set fish_bind_mode insert + case yank + commandline -f begin-selection + for i in (seq $total) + commandline -f $motion + end + commandline -f kill-selection yank end-selection repaint-mode + case swap-case + commandline -f begin-selection + for i in (seq $total) + commandline -f $motion + end + commandline -f togglecase-selection end-selection repaint-mode + end + end + set -g __fish_vi_operator +end + +function fish_vi_move_end_word + set -l cmd $argv[1] + set fish_cursor_end_mode exclusive + commandline -f forward-single-char $cmd backward-char + set fish_cursor_end_mode inclusive +end + # TODO: Currently we do not support hexadecimal and octal values. function fish_vi_inc_dec --description 'increment or decrement the number below the cursor' # The cursor is zero based, but all string functions assume 1 to be @@ -146,8 +257,37 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' # Default (command) mode bind -s --preset :,q exit bind -s --preset -m insert ctrl-c clear-commandline repaint-mode - bind -s --preset -M default h backward-char - bind -s --preset -M default l forward-char + + bind -s --preset -M default escape 'set -g __fish_vi_count' + bind -s --preset -M default ctrl-\[ 'set -g __fish_vi_count' + + for i in (seq 1 9) + bind -s --preset -M default $i "fish_vi_arg_digit $i" + end + # 0 is special: it is 'beginning-of-line' unless we are already counting (e.g. 10) + bind -s --preset -M default 0 "if test -n \"\$__fish_vi_count\"; fish_vi_arg_digit 0; else; commandline -f beginning-of-line; end" + + # --- Movement with Count Support --- + bind -s --preset -M default h 'fish_vi_run_count backward-char' + bind -s --preset -M default l 'fish_vi_run_count forward-char' + + bind -s --preset -M default k 'fish_vi_run_count up-or-search' + bind -s --preset -M default j 'fish_vi_run_count down-or-search' + + bind -s --preset -M default b 'fish_vi_run_count backward-word' + bind -s --preset -M default B 'fish_vi_run_count backward-bigword' + bind -s --preset -M default g,e 'fish_vi_run_count backward-word' + bind -s --preset -M default g,E 'fish_vi_run_count backward-bigword' + + bind -s --preset -M default w 'fish_vi_run_count forward-word forward-single-char' + bind -s --preset -M default W 'fish_vi_run_count forward-bigword forward-single-char' + + bind -s --preset -M default e 'fish_vi_run_count fish_vi_move_end_word forward-word' + bind -s --preset -M default E 'fish_vi_run_count fish_vi_move_end_word forward-bigword' + + bind -s --preset -M default x 'fish_vi_run_count delete-char' + bind -s --preset -M default X 'fish_vi_run_count backward-delete-char' + bind -s --preset -m insert enter execute bind -s --preset -m insert ctrl-j execute bind -s --preset -m insert ctrl-m execute @@ -165,7 +305,8 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' for key in $eol_keys bind -s --preset $key end-of-line end - for key in $bol_keys + # Note: 0 is handled in the numeric section above + for key in \^ g\^ _ bind -s --preset $key beginning-of-line end @@ -176,17 +317,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset ] history-token-search-forward bind -s --preset -m insert / history-pager repaint-mode - bind -s --preset k up-or-search - bind -s --preset j down-or-search - bind -s --preset b backward-word - bind -s --preset B backward-bigword - bind -s --preset g,e backward-word - bind -s --preset g,E backward-bigword - bind -s --preset w forward-word forward-single-char - bind -s --preset W forward-bigword forward-single-char - bind -s --preset e 'set fish_cursor_end_mode exclusive' forward-single-char forward-word backward-char 'set fish_cursor_end_mode inclusive' - bind -s --preset E 'set fish_cursor_end_mode exclusive' forward-single-char forward-bigword backward-char 'set fish_cursor_end_mode inclusive' - bind -s --preset -M insert ctrl-n accept-autosuggestion # Vi/Vim doesn't support these keys in insert mode but that seems silly so we do so anyway. @@ -195,8 +325,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M insert end end-of-line bind -s --preset -M default end end-of-line - bind -s --preset -M default x delete-char - bind -s --preset -M default X backward-delete-char bind -s --preset -M insert delete delete-char bind -s --preset -M default delete delete-char @@ -207,29 +335,58 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M insert ctrl-h backward-delete-char bind -s --preset -M default ctrl-h backward-char - bind -s --preset d,d kill-whole-line + # Operators & Operator Mode + bind -s --preset -M default d 'fish_vi_start_operator delete' + bind -s --preset -M default c 'fish_vi_start_operator change' + bind -s --preset -M default y 'fish_vi_start_operator yank' + bind -s --preset -M default g,\~ 'fish_vi_start_operator swap-case' + + bind -s --preset -M operator escape fish_vi_operator_cancel + bind -s --preset -M operator ctrl-\[ fish_vi_operator_cancel + + for i in (seq 1 9) + bind -s --preset -M operator $i "fish_vi_arg_digit $i" + end + bind -s --preset -M operator 0 "if test -n \"\$__fish_vi_count\"; fish_vi_arg_digit 0; else; fish_vi_exec_motion beginning-of-line; end" + + bind -s --preset -M operator h 'fish_vi_exec_motion backward-char' + bind -s --preset -M operator l 'fish_vi_exec_motion forward-char' + bind -s --preset -M operator k 'fish_vi_exec_motion up-line' + bind -s --preset -M operator j 'fish_vi_exec_motion down-line' + bind -s --preset -M operator b 'fish_vi_exec_motion backward-word' + bind -s --preset -M operator B 'fish_vi_exec_motion backward-bigword' + bind -s --preset -M operator g,e 'fish_vi_exec_motion backward-word' + bind -s --preset -M operator g,E 'fish_vi_exec_motion backward-bigword' + bind -s --preset -M operator w 'fish_vi_exec_motion forward-word' + bind -s --preset -M operator W 'fish_vi_exec_motion forward-bigword' + bind -s --preset -M operator e 'fish_vi_exec_motion forward-single-char forward-word backward-char' + bind -s --preset -M operator E 'fish_vi_exec_motion forward-single-char forward-bigword backward-char' + + bind -s --preset -M operator 0 'fish_vi_exec_motion beginning-of-line' + bind -s --preset -M operator \^ 'fish_vi_exec_motion beginning-of-line' + bind -s --preset -M operator \$ 'fish_vi_exec_motion end-of-line' + + bind -s --preset -M operator f 'fish_vi_exec_motion forward-jump' + bind -s --preset -M operator F 'fish_vi_exec_motion backward-jump' + bind -s --preset -M operator t 'fish_vi_exec_motion forward-jump-till' + bind -s --preset -M operator T 'fish_vi_exec_motion backward-jump-till' + bind -s --preset -M operator ';' 'fish_vi_exec_motion repeat-jump' + bind -s --preset -M operator , 'fish_vi_exec_motion repeat-jump-reverse' + + bind -s --preset -M operator d 'fish_vi_exec_motion --linewise' + bind -s --preset -M operator c 'fish_vi_exec_motion --linewise' + bind -s --preset -M operator y 'fish_vi_exec_motion --linewise' + bind -s --preset -M operator \~ 'fish_vi_exec_motion --linewise' + bind -s --preset D kill-line bind -s --preset d,\$ kill-line bind -s --preset d,\^ backward-kill-line bind -s --preset d,0 backward-kill-line - bind -s --preset d,w kill-word - bind -s --preset d,W kill-bigword + bind -s --preset d,i,w forward-single-char forward-single-char backward-word kill-word bind -s --preset d,i,W forward-single-char forward-single-char backward-bigword kill-bigword bind -s --preset d,a,w forward-single-char forward-single-char backward-word kill-word bind -s --preset d,a,W forward-single-char forward-single-char backward-bigword kill-bigword - bind -s --preset d,e kill-word - bind -s --preset d,E kill-bigword - bind -s --preset d,b backward-kill-word - bind -s --preset d,B backward-kill-bigword - bind -s --preset d,g,e backward-kill-word - bind -s --preset d,g,E backward-kill-bigword - bind -s --preset d,f begin-selection forward-jump kill-selection end-selection - bind -s --preset d,t begin-selection forward-jump backward-char kill-selection end-selection - bind -s --preset d,F begin-selection backward-jump kill-selection end-selection - bind -s --preset d,T begin-selection backward-jump forward-single-char kill-selection end-selection - bind -s --preset d,h backward-char delete-char - bind -s --preset d,l delete-char bind -s --preset d,i,b jump-till-matching-bracket and jump-till-matching-bracket and begin-selection jump-till-matching-bracket kill-selection end-selection bind -s --preset d,a,b jump-to-matching-bracket and jump-to-matching-bracket and begin-selection jump-to-matching-bracket kill-selection end-selection bind -s --preset d,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection @@ -239,42 +396,28 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -m insert s delete-char repaint-mode bind -s --preset -m insert S kill-inner-line repaint-mode - bind -s --preset -m insert c,c kill-inner-line repaint-mode bind -s --preset -m insert C kill-line repaint-mode bind -s --preset -m insert c,\$ kill-line repaint-mode bind -s --preset -m insert c,\^ backward-kill-line repaint-mode bind -s --preset -m insert c,0 backward-kill-line repaint-mode - bind -s --preset -m insert c,w kill-word repaint-mode - bind -s --preset -m insert c,W kill-bigword repaint-mode + bind -s --preset -m insert c,i,w forward-single-char forward-single-char backward-word kill-word repaint-mode bind -s --preset -m insert c,i,W forward-single-char forward-single-char backward-bigword kill-bigword repaint-mode bind -s --preset -m insert c,a,w forward-single-char forward-single-char backward-word kill-word repaint-mode bind -s --preset -m insert c,a,W forward-single-char forward-single-char backward-bigword kill-bigword repaint-mode - bind -s --preset -m insert c,e kill-word repaint-mode - bind -s --preset -m insert c,E kill-bigword repaint-mode - bind -s --preset -m insert c,b backward-kill-word repaint-mode - bind -s --preset -m insert c,B backward-kill-bigword repaint-mode - bind -s --preset -m insert c,g,e backward-kill-word repaint-mode - bind -s --preset -m insert c,g,E backward-kill-bigword repaint-mode - bind -s --preset -m insert c,f begin-selection forward-jump kill-selection end-selection repaint-mode - bind -s --preset -m insert c,t begin-selection forward-jump backward-char kill-selection end-selection repaint-mode - bind -s --preset -m insert c,F begin-selection backward-jump kill-selection end-selection repaint-mode - bind -s --preset -m insert c,T begin-selection backward-jump forward-single-char kill-selection end-selection repaint-mode - bind -s --preset -m insert c,h backward-char begin-selection kill-selection end-selection repaint-mode - bind -s --preset -m insert c,l begin-selection kill-selection end-selection repaint-mode bind -s --preset -m insert c,i,b jump-till-matching-bracket and jump-till-matching-bracket and begin-selection jump-till-matching-bracket kill-selection end-selection bind -s --preset -m insert c,a,b jump-to-matching-bracket and jump-to-matching-bracket and begin-selection jump-to-matching-bracket kill-selection end-selection bind -s --preset -m insert c,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection repaint-mode bind -s --preset -m insert c,a backward-jump and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection repaint-mode - bind -s --preset '~' togglecase-char forward-single-char + bind -s --preset \~ togglecase-char forward-single-char bind -s --preset g,u downcase-word bind -s --preset g,U upcase-word bind -s --preset J end-of-line delete-char bind -s --preset K 'man (commandline -t) 2>/dev/null; or echo -n \a' - bind -s --preset yy kill-whole-line yank + # yy handled by operator mode for seq in '",*,y,y' '",*,Y' '",+,y,y' '",+,Y' bind -s --preset $seq fish_clipboard_copy end @@ -282,24 +425,11 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset y,\$ kill-line yank bind -s --preset y,\^ backward-kill-line yank bind -s --preset y,0 backward-kill-line yank - bind -s --preset y,w kill-word yank - bind -s --preset y,W kill-bigword yank + bind -s --preset y,i,w forward-single-char forward-single-char backward-word kill-word yank bind -s --preset y,i,W forward-single-char forward-single-char backward-bigword kill-bigword yank bind -s --preset y,a,w forward-single-char forward-single-char backward-word kill-word yank bind -s --preset y,a,W forward-single-char forward-single-char backward-bigword kill-bigword yank - bind -s --preset y,e kill-word yank - bind -s --preset y,E kill-bigword yank - bind -s --preset y,b backward-kill-word yank - bind -s --preset y,B backward-kill-bigword yank - bind -s --preset y,g,e backward-kill-word yank - bind -s --preset y,g,E backward-kill-bigword yank - bind -s --preset y,f begin-selection forward-jump kill-selection yank end-selection - bind -s --preset y,t begin-selection forward-jump-till kill-selection yank end-selection - bind -s --preset y,F begin-selection backward-jump kill-selection yank end-selection - bind -s --preset y,T begin-selection backward-jump-till kill-selection yank end-selection - bind -s --preset y,h backward-char begin-selection kill-selection yank end-selection - bind -s --preset y,l begin-selection kill-selection yank end-selection bind -s --preset y,i,b jump-till-matching-bracket and jump-till-matching-bracket and begin-selection jump-till-matching-bracket kill-selection yank end-selection bind -s --preset y,a,b jump-to-matching-bracket and jump-to-matching-bracket and begin-selection jump-to-matching-bracket kill-selection yank end-selection bind -s --preset y,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump kill-selection yank end-selection @@ -404,7 +534,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -s --preset -M visual -m default y kill-selection yank end-selection repaint-mode bind -s --preset -M visual -m default '",*,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" bind -s --preset -M visual -m default '",+,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" - bind -s --preset -M visual -m default '~' togglecase-selection end-selection repaint-mode + bind -s --preset -M visual -m default \~ togglecase-selection end-selection repaint-mode bind -s --preset -M visual -m default g,u downcase-selection end-selection repaint-mode bind -s --preset -M visual -m default g,U upcase-selection end-selection repaint-mode diff --git a/share/prompts/nim.fish b/share/prompts/nim.fish index 7acaed3ae..b4d1ffec0 100644 --- a/share/prompts/nim.fish +++ b/share/prompts/nim.fish @@ -86,6 +86,8 @@ function fish_prompt switch $fish_bind_mode case default set mode (set_color --bold red)N + case operator + set mode (set_color --bold cyan)N case insert set mode (set_color --bold green)I case replace_one diff --git a/tests/pexpects/bind.py b/tests/pexpects/bind.py index fe287f573..7552783d4 100644 --- a/tests/pexpects/bind.py +++ b/tests/pexpects/bind.py @@ -270,10 +270,58 @@ sleep(0.200) send("0$i34\r") expect_prompt("echo 12345") +# Test operator mode with count (d3w) +send("echo one two three four five") +send("\033") +sleep(0.200) +send("0w") +send("d3w") +sendline("") +expect_prompt("echo four five") + +# Test count before operator (3dw) +send("echo one two three four five") +send("\033") +sleep(0.200) +send("0w") +send("3dw") +sendline("") +expect_prompt("echo four five") + +# Test count on both (2d2w -> 4 words) +send("echo one two three four five six") +send("\033") +sleep(0.200) +send("0w") +send("2d2w") +sendline("") +expect_prompt("echo five six") + +# Test change operator with count (c2w) +send("echo one two three") +send("\033") +sleep(0.200) +send("0w") +send("c2wREPLACED") +sendline("") +expect_prompt("echo REPLACEDthree") + +# Test escape cancelling count +send("echo one two three") +send("\033") +sleep(0.200) +send("0w") +send("3") +send("\033") +sleep(0.100) +send("dw") +sendline("") +expect_prompt("echo two three") + # Now test that exactly the expected bind modes are defined sendline("bind --list-modes") expect_prompt( - "default\r\ninsert\r\nreplace\r\nreplace_one\r\nvisual\r\n", + "default\r\ninsert\r\noperator\r\nreplace\r\nreplace_one\r\nvisual\r\n", unmatched="Unexpected vi bind modes", ) diff --git a/tests/pexpects/bind_mode_events.py b/tests/pexpects/bind_mode_events.py index f51156f10..f5ff34c1c 100644 --- a/tests/pexpects/bind_mode_events.py +++ b/tests/pexpects/bind_mode_events.py @@ -37,12 +37,20 @@ sleep(10 if "CI" in os.environ else 1) send("\033") sleep(10 if "CI" in os.environ else 1) +# operator mode +send("d") +sleep(10 if "CI" in os.environ else 1) + +# back to normal mode +send("\033") +sleep(10 if "CI" in os.environ else 1) + # insert mode again send("i") sleep(10 if "CI" in os.environ else 1) send("echo mode changes: $MODE_CHANGES\r") -expect_prompt("\r\n.*mode changes: default insert default insert\r\n") +expect_prompt("\r\n.*mode changes: default insert default operator default insert\r\n") # Regression test for #8125. # Control-C should return us to insert mode.