fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
308aaa3f0
master
1function fish_vi_dec 2fish_vi_inc_dec dec 3end 4 5function fish_vi_inc 6fish_vi_inc_dec inc 7end 8 9function fish_vi_arg_digit --description'Accumulate a digit for the next command' 10set -g __fish_vi_count" $__fish_vi_count$argv [ 1 ] " 11end 12 13function fish_vi_run_count --description'Run a command $__fish_vi_count times' 14set -l count( __fish_vi_consume_count __fish_vi_count) 15 16for iin ( seq $count ) 17if functions -q --$argv [ 1 ] 18$argv 19else 20commandline -f$argv 21end 22end 23end 24 25function fish_vi_start_operator 26set -g __fish_vi_operator$argv [ 1 ] 27set -g __fish_vi_start_count( __fish_vi_consume_count __fish_vi_count) 28set fish_bind_mode operator 29commandline -f repaint-mode 30end 31 32function fish_vi_operator_cancel 33set -g __fish_vi_operator 34set -g __fish_vi_start_count 35set -g __fish_vi_count 36set fish_bind_mode default 37commandline -f repaint-mode 38end 39 40function __fish_vi_consume_count -a varname 41set -l effective_count$$varname 42if test -z " $effective_count " 43set effective_count1 44end 45set -g$varname 46echo $effective_count 47end 48 49function __fish_vi_delete_char 50set -l count( __fish_vi_consume_count __fish_vi_count) 51commandline -f begin-selection 52if test $count -gt 1 53for iin ( seq 1 ( math $count -1 )) 54commandline -f forward-char 55end 56end 57commandline -f kill-selection end-selection 58end 59 60function __fish_vi_backward_delete_char 61set -l count( __fish_vi_consume_count __fish_vi_count) 62set -l start_cursor( commandline -C) 63if test $start_cursor -eq 0 64return 65end 66commandline -f backward-char 67commandline -f begin-selection 68if test $count -gt 1 69for iin ( seq 1 ( math $count -1 )) 70commandline -f backward-char 71end 72end 73commandline -f kill-selection end-selection 74end 75 76function fish_vi_yank_selection 77set -g fish_cursor_end_mode exclusive 78commandline -f kill-selection -f yank 79set -g fish_cursor_end_mode inclusive 80end 81 82function fish_vi_exec_motion 83argparse --stop-nonopt linewise --$argv 84or return 85 86set -l motion$argv 87set -l total( math ( __fish_vi_consume_count __fish_vi_start_count) \* ( __fish_vi_consume_count __fish_vi_count)) 88 89set fish_bind_mode default 90 91set -l seq_total( seq $total ) 92if set -ql _flag_linewise 93switch $__fish_vi_operator 94case delete 95for iin $seq_total 96commandline -f kill-whole-line 97end 98case change 99for iin $seq_total 100commandline -f kill-inner-line 101end 102set fish_bind_mode insert 103case yank 104for iin $seq_total 105commandline -f kill-whole-line yank 106end 107case swap-case 108# Not implemented yet 109return 110end 111else 112set -l use_selection true 113set -l swap_case_hack 114switch $motion [ 1 ] 115case forward-word-vi forward-bigword-vi 116if test $__fish_vi_operator = swap-case 117set swap_case_hack( string replace -r --'^forward-((?:big)?word)-vi$' '$1' $motion ) 118else 119set use_selection false 120# kill-word-vi kill-bigword-vi 121set motion( string replace -- forward kill$motion ) 122end 123end 124set -l motion_cmd 125switch $motion [ 1 ] 126case commandline 127set motion_cmd$motion 128case '*' 129set motion_cmd commandline -f$motion 130end 131switch $motion [ 1 ] 132case forward-char 133set -e seq_total[ 1 ] 134case backward-char 135$motion_cmd 136set -e seq_total[ 1 ] 137end 138if $use_selection 139commandline -f begin-selection 140else 141commandline -f begin-undo-group 142end 143set -l ok true 144switch $__fish_vi_operator 145case delete 146for iin $seq_total 147$motion_cmd || { set ok false; break} 148end 149if $ok && $use_selection 150commandline -f kill-selection 151end 152case change 153switch $motion [ 1 ] 154case kill-word-vi kill-bigword-vi 155set -l end_kill( string replace -- -vi'' $motion [ 1 ]) 156for iin $seq_total 157if test $i -eq $total 158commandline -f$end_kill 159else 160$motion_cmd 161end 162end 163case '*' 164for iin $seq_total 165$motion_cmd || { set ok false; break} 166end 167end 168if $ok 169if $use_selection 170commandline -f kill-selection 171end 172set fish_bind_mode insert 173end 174case yank 175for iin $seq_total 176$motion_cmd || { set ok false; break} 177end 178if $ok 179if $use_selection 180fish_vi_yank_selection 181else 182commandline -f yank 183end 184end 185case swap-case 186for iin $seq_total 187$motion_cmd || { set ok false; break} 188end 189if $ok 190if set -q swap_case_hack[ 1 ] 191set -l word$swap_case_hack 192commandline -f\ 193 backward-$word \ 194 forward-$word -end\ 195 togglecase-selection\ 196 backward-$word \ 197 forward-$word -vi 198else 199commandline -f togglecase-selection 200end 201end 202end 203if $use_selection 204commandline -f end-selection 205else 206commandline -f end-undo-group 207end 208end 209commandline -f repaint-mode 210set -g __fish_vi_operator 211end 212 213# TODO: Currently we do not support hexadecimal and octal values. 214function fish_vi_inc_dec --description'increment or decrement the number below the cursor' 215# The cursor is zero based, but all string functions assume 1 to be 216# the lowest index. Adjust accordingly. 217set --local cursor( math --( commandline --cursor) +1 ) 218set --local line( commandline --current-buffer| string collect) 219 220set --local candidate( string sub --start$cursor --$line | string collect) 221if set --local just_found( string match --regex'^-?[0-9]+' --$candidate ) 222# Search from the current cursor position backwards for as long as we 223# can identify a valid number. 224set --function found$just_found 225set --function found_at$cursor 226set --local end( math --$cursor +( string length --$found ) -1 ) 227 228set i( math --$cursor -1 ) 229while [ $i -ge 1 ] 230set candidate( string sub --start$i --end$end --$line ) 231if set just_found( string match --regex'^-?[0-9]+$' --$candidate ) 232set found$just_found 233set found_at$i 234# We found a candidate, but continue to make sure that we captured 235# the complete number and not just part of it. 236else 237# We have already found a number earlier. Work with that. 238break 239end 240 241set i( math --$i -1 ) 242end 243else 244# We didn't find a match below the cursor. Mirror Vim behavior by 245# checking ahead as well. 246for iin ( seq ( math --$cursor +1 ) ( math --( string length --$line ) -1 )) 247set candidate( string sub --start$i --$line | string collect) 248 249if set just_found( string match --regex'^-?[0-9]+' --$candidate ) 250set found$just_found 251set found_at$i 252break 253end 254end 255 256if [ -z " $found " ] 257return 258end 259end 260 261if [ $argv = inc] 262set number( math --$found +1 ) 263else if [ $argv = dec] 264set number( math --$found -1 ) 265end 266 267set --local number_abs( string trim --left --chars=- --$number ) 268set --local signed$status 269set --local found_abs( string trim --left --chars=- --$found ) 270set number( string pad --char0 --width( string length --$found_abs ) --$number_abs ) 271if test $signed -eq 0 272set number"- $number " 273end 274 275# `string sub` may bitch about `--end` being zero if `found_at` is 1. 276# So ignore errors here... 277set --local before( string sub --end( math --$found_at -1 ) --$line 2> /dev/null| string collect) 278set --local after( string sub --start( math --$found_at +( string length --$found )) --$line | string collect) 279commandline --replace --" $before$number$after " 280# Need to subtract two here because 1) cursor is zero based 2) 281# `found_at` is the index of the first character of the match, but we 282# want the one before that. 283commandline --cursor --( math --$found_at +( string length --$number ) -2 ) 284commandline --function -- repaint 285end 286 287function fish_vi_key_bindings --description'vi-like key bindings for fish' 288if contains -- -h$argv 289or contains -- --help$argv 290echo "Sorry but this function doesn't support -h or --help" >&2 291return 1 292end 293 294# Erase all bindings if not explicitly requested otherwise to 295# allow for hybrid bindings. 296# This needs to be checked here because if we are called again 297# via the variable handler the argument will be gone. 298set -l rebind true 299if test " $argv [ 1 ] " = --no-erase 300set rebind false 301set -e argv[ 1 ] 302else 303bind --erase --all --preset# clear earlier bindings, if any 304end 305 306# Allow just calling this function to correctly set the bindings. 307# Because it's a rather discoverable name, users will execute it 308# and without this would then have subtly broken bindings. 309if test " $fish_key_bindings " != fish_vi_key_bindings 310and test " $rebind " = true 311__fish_change_key_bindings fish_vi_key_bindings 312end 313 314set -l init_mode insert 315# These are only the special vi-style keys 316# not end/home, we share those. 317set -l eol_keys\$ g,\$ 318set -l bol_keys\^ 0 g\^ _ 319 320if contains --$argv [ 1 ] insert default visual 321set init_mode$argv [ 1 ] 322else if set -q argv[ 1 ] 323# We should still go on so the bindings still get set. 324echo "Unknown argument $argv " >&2 325end 326 327function __fish_vi_key_bindings_shared 328eval "$ ( __fish_shared_key_bindings ) " 329end 330 331# Inherit shared key bindings. 332# Do this first so vi-bindings win over default. 333for modein insert default visual 334__fish_vi_key_bindings_shared -M$mode 335end 336functions -e __fish_vi_key_bindings_shared 337 338# Add a way to switch from insert to normal (command) mode. 339# Note if we are paging, we want to stay in insert mode 340# See #2871 341set -l on_escape' 342if commandline -P 343commandline -f cancel 344else 345set fish_bind_mode default 346if test (count (commandline --cut-at-cursor | tail -c2)) != 2 347commandline -f backward-char 348end 349commandline -f repaint-mode 350end 351' 352bind --preset -M insert escape$on_escape 353bind --preset -M insert ctrl-\[ $on_escape 354 355# Default (command) mode 356bind --preset :,q exit 357bind --preset -m insert ctrl-c clear-commandline repaint-mode 358 359bind --preset -M default escape'set -g __fish_vi_count' 360bind --preset -M default ctrl-\[ 'set -g __fish_vi_count' 361 362for iin ( seq 1 9 ) 363bind --preset -M default$i "fish_vi_arg_digit $i " 364end 365# 0 is special: it is 'beginning-of-line' unless we are already counting (e.g. 10) 366bind --preset -M default0 "if test -n \"\$__fish_vi_count\"; fish_vi_arg_digit 0; else; commandline -f beginning-of-line; end" 367 368# --- Movement with Count Support --- 369bind --preset -M default h'fish_vi_run_count backward-char' 370bind --preset -M default l'fish_vi_run_count forward-char' 371 372bind --preset -M default k'fish_vi_run_count up-or-search' 373bind --preset -M default j'fish_vi_run_count down-or-search' 374 375bind --preset -M default b'fish_vi_run_count backward-word' 376bind --preset -M default B'fish_vi_run_count backward-bigword' 377bind --preset -M default g,e'fish_vi_run_count backward-word-end' 378bind --preset -M default g,E'fish_vi_run_count backward-bigword-end' 379 380bind --preset -M default w'fish_vi_run_count forward-word-vi' 381bind --preset -M default W'fish_vi_run_count forward-bigword-vi' 382 383bind --preset -M default e'fish_vi_run_count forward-word-end' 384bind --preset -M default E'fish_vi_run_count forward-bigword-end' 385 386bind --preset -M default x __fish_vi_delete_char 387bind --preset -M default X __fish_vi_backward_delete_char 388 389bind --preset -m insert enter execute 390bind --preset -m insert ctrl-j execute 391bind --preset -m insert ctrl-m execute 392bind --preset -m insert o'set fish_cursor_end_mode exclusive' insert-line-under repaint-mode 393bind --preset -m insert O'set fish_cursor_end_mode exclusive' insert-line-over repaint-mode 394bind --preset -m insert i repaint-mode 395bind --preset -m insert I beginning-of-line repaint-mode 396bind --preset -m insert a'set fish_cursor_end_mode exclusive' forward-single-char repaint-mode 397bind --preset -m insert A'set fish_cursor_end_mode exclusive' end-of-line repaint-mode 398bind --preset -m visual v begin-selection repaint-mode 399 400bind --preset g,g beginning-of-buffer 401bind --preset G end-of-buffer 402 403for keyin $eol_keys 404bind --preset$key end-of-line 405end 406# Note: 0 is handled in the numeric section above 407for keyin \^ g\^ _ 408bind --preset$key beginning-of-line 409end 410 411bind --preset u undo 412bind --preset ctrl-r redo 413 414bind --preset[ history-token-search-backward 415bind --preset] history-token-search-forward 416bind --preset -m insert / history-pager repaint-mode 417 418bind --preset -M insert ctrl-n accept-autosuggestion 419 420# Vi/Vim doesn't support these keys in insert mode but that seems silly so we do so anyway. 421bind --preset -M insert home beginning-of-line 422bind --preset -M default home beginning-of-line 423bind --preset -M insert end end-of-line 424bind --preset -M default end end-of-line 425 426bind --preset -M insert delete delete-char 427bind --preset -M default delete delete-char 428 429# Backspace deletes a char in insert mode, but not in normal/default mode. 430bind --preset -M insert backspace backward-delete-char 431bind --preset -M insert shift-backspace backward-delete-char 432bind --preset -M default backspace backward-char 433bind --preset -M insert ctrl-h backward-delete-char 434bind --preset -M default ctrl-h backward-char 435 436# Operators & Operator Mode 437bind --preset -M default d'fish_vi_start_operator delete' 438bind --preset -M default c'fish_vi_start_operator change' 439bind --preset -M default y'fish_vi_start_operator yank' 440bind --preset -M default g,\~ 'fish_vi_start_operator swap-case' 441 442bind --preset -M operator escape fish_vi_operator_cancel 443bind --preset -M operator ctrl-\[ fish_vi_operator_cancel 444 445for iin ( seq 1 9 ) 446bind --preset -M operator$i "fish_vi_arg_digit $i " 447end 448bind --preset -M operator0 "if test -n \"\$__fish_vi_count\"; fish_vi_arg_digit 0; else; fish_vi_exec_motion beginning-of-line; end" 449 450bind --preset -M operator h'fish_vi_exec_motion backward-char' 451bind --preset -M operator l'fish_vi_exec_motion forward-char' 452bind --preset -M operator k'fish_vi_exec_motion up-line' 453bind --preset -M operator j'fish_vi_exec_motion down-line' 454bind --preset -M operator b'fish_vi_exec_motion backward-word' 455bind --preset -M operator B'fish_vi_exec_motion backward-bigword' 456bind --preset -M operator g,e'fish_vi_exec_motion backward-word-end' 457bind --preset -M operator g,E'fish_vi_exec_motion backward-bigword-end' 458bind --preset -M operator w'fish_vi_exec_motion forward-word-vi' 459bind --preset -M operator W'fish_vi_exec_motion forward-bigword-vi' 460bind --preset -M operator e'fish_vi_exec_motion forward-word-end' 461bind --preset -M operator E'fish_vi_exec_motion forward-bigword-end' 462 463bind --preset -M operator0 'fish_vi_exec_motion beginning-of-line' 464bind --preset -M operator\^ 'fish_vi_exec_motion beginning-of-line' 465bind --preset -M operator\$ 'fish_vi_exec_motion end-of-line' 466 467bind --preset -M operator f --sets-mode f'' 468bind --preset -M operator F --sets-mode F'' 469bind --preset -M operator t --sets-mode t'' 470bind --preset -M operator T --sets-mode T'' 471 472bind --preset -M f'' get-key'fish_vi_exec_motion commandline --forward-jump=$fish_key' 'set -eg fish_key' 473bind --preset -M F'' get-key'fish_vi_exec_motion commandline --backward-jump=$fish_key' 'set -eg fish_key' 474bind --preset -M t'' get-key'fish_vi_exec_motion commandline --forward-jump-till=$fish_key' 'set -eg fish_key' 475bind --preset -M T'' get-key'fish_vi_exec_motion commandline --backward-jump-till=$fish_key' 'set -eg fish_key' 476 477bind --preset -M operator';' 'fish_vi_exec_motion repeat-jump' 478bind --preset -M operator ,'fish_vi_exec_motion repeat-jump-reverse' 479 480bind --preset -M operator d'fish_vi_exec_motion --linewise' 481bind --preset -M operator c'fish_vi_exec_motion --linewise' 482bind --preset -M operator y'fish_vi_exec_motion --linewise' 483bind --preset -M operator\~ 'fish_vi_exec_motion --linewise' 484 485bind --preset D kill-line 486bind --preset d,\$ kill-line 487bind --preset d,\^ backward-kill-line 488bind --preset d,0 backward-kill-line 489 490bind --preset d,i,w kill-inner-word 491bind --preset d,i,W kill-inner-bigword 492bind --preset d,a,w kill-a-word 493bind --preset d,a,W kill-a-bigword 494bind --preset d,i,b jump-till-matching-bracket and jump-till-matching-bracket and begin-selection jump-till-matching-bracket kill-selection end-selection 495bind --preset d,a,b jump-to-matching-bracket and jump-to-matching-bracket and begin-selection jump-to-matching-bracket kill-selection end-selection 496bind --preset d,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection 497bind --preset d,a backward-jump and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection 498bind --preset'd,;' begin-selection repeat-jump kill-selection end-selection 499bind --preset'd,comma' begin-selection repeat-jump-reverse kill-selection end-selection 500 501bind --preset -m insert s delete-char repaint-mode 502bind --preset -m insert S kill-inner-line repaint-mode 503bind --preset -m insert C kill-line repaint-mode 504bind --preset -m insert c,\$ kill-line repaint-mode 505bind --preset -m insert c,\^ backward-kill-line repaint-mode 506bind --preset -m insert c,0 backward-kill-line repaint-mode 507 508bind --preset -m insert c,i,w kill-inner-word repaint-mode 509bind --preset -m insert c,i,W kill-inner-bigword repaint-mode 510bind --preset -m insert c,a,w kill-a-word repaint-mode 511bind --preset -m insert c,a,W kill-a-bigword repaint-mode 512bind --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 513bind --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 514bind --preset -m insert c,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection repaint-mode 515bind --preset -m insert c,a backward-jump and repeat-jump-reverse and begin-selection repeat-jump kill-selection end-selection repaint-mode 516 517bind --preset\~ togglecase-char forward-single-char 518bind --preset g,u downcase-word 519bind --preset g,U upcase-word 520 521bind --preset J end-of-line delete-char 522bind --preset K'man (commandline -t) 2>/dev/null; or echo -n \a' 523 524# yy handled by operator mode 525for seqin '",*,y,y' '",*,Y' '",+,y,y' '",+,Y' 526bind --preset$seq fish_clipboard_copy 527end 528bind --preset Y kill-whole-line yank 529bind --preset y,\$ kill-line yank 530bind --preset y,\^ backward-kill-line yank 531bind --preset y,0 backward-kill-line yank 532bind --preset y,i,w kill-inner-word yank 533bind --preset y,i,W kill-inner-bigword yank 534bind --preset y,a,w kill-a-word yank 535bind --preset y,a,W kill-a-bigword yank 536bind --preset y,i,b jump-till-matching-bracket and jump-till-matching-bracket and begin-selection jump-till-matching-bracket fish_vi_yank_selection end-selection 537bind --preset y,a,b jump-to-matching-bracket and jump-to-matching-bracket and begin-selection jump-to-matching-bracket fish_vi_yank_selection end-selection 538bind --preset y,i backward-jump-till and repeat-jump-reverse and begin-selection repeat-jump fish_vi_yank_selection end-selection 539bind --preset y,a backward-jump and repeat-jump-reverse and begin-selection repeat-jump fish_vi_yank_selection end-selection 540 541bind --preset % jump-to-matching-bracket 542bind --preset f forward-jump 543bind --preset F backward-jump 544bind --preset t forward-jump-till 545bind --preset T backward-jump-till 546bind --preset';' repeat-jump 547bind --preset , repeat-jump-reverse 548 549# in emacs yank means paste 550# in vim p means paste *after* current character, so go forward a char before pasting 551# also in vim, P means paste *at* current position (like at '|' with cursor = line), 552# \ so there's no need to go back a char, just paste it without moving 553bind --preset p'set -g fish_cursor_end_mode exclusive' forward-char'set -g fish_cursor_end_mode inclusive' yank 554bind --preset P yank 555bind --preset g,p yank-pop 556 557# same vim 'pasting' note as upper 558bind --preset'",*,p' 'set -g fish_cursor_end_mode exclusive' forward-char'set -g fish_cursor_end_mode inclusive' fish_clipboard_paste 559bind --preset'",*,P' fish_clipboard_paste 560bind --preset'",+,p' 'set -g fish_cursor_end_mode exclusive' forward-char'set -g fish_cursor_end_mode inclusive' fish_clipboard_paste 561bind --preset'",+,P' fish_clipboard_paste 562 563# 564# Lowercase r, enters replace_one mode 565# 566bind --preset -m replace_one r repaint-mode 567bind --preset -M replace_one -m default'' 'set -g fish_cursor_end_mode exclusive' delete-char self-insert backward-char repaint-mode'set -g fish_cursor_end_mode inclusive' 568bind --preset -M replace_one -m default enter'set -g fish_cursor_end_mode exclusive' 'commandline -f delete-char; commandline -i \n; commandline -f backward-char' repaint-mode'set -g fish_cursor_end_mode inclusive' 569bind --preset -M replace_one -m default ctrl-j'set -g fish_cursor_end_mode exclusive' 'commandline -f delete-char; commandline -i \n; commandline -f backward-char' repaint-mode'set -g fish_cursor_end_mode inclusive' 570bind --preset -M replace_one -m default ctrl-m'set -g fish_cursor_end_mode exclusive' 'commandline -f delete-char; commandline -i \n; commandline -f backward-char' repaint-mode'set -g fish_cursor_end_mode inclusive' 571bind --preset -M replace_one -m default escape cancel repaint-mode 572bind --preset -M replace_one -m default ctrl-\[ cancel repaint-mode 573 574# 575# Uppercase R, enters replace mode 576# 577bind --preset -m replace R repaint-mode 578bind --preset -M replace'' delete-char self-insert 579bind --preset -M replace -m insert enter execute repaint-mode 580bind --preset -M replace -m insert ctrl-j execute repaint-mode 581bind --preset -M replace -m insert ctrl-m execute repaint-mode 582bind --preset -M replace -m default escape cancel repaint-mode 583bind --preset -M replace -m default ctrl-\[ cancel repaint-mode 584# in vim (and maybe in vi), <BS> deletes the changes 585# but this binding just move cursor backward, not delete the changes 586bind --preset -M replace backspace backward-char 587bind --preset -M replace shift-backspace backward-char 588 589# 590# Increment or decrement number under the cursor with ctrl+x ctrl+a 591# 592bind --preset -M default ctrl-a fish_vi_inc 593bind --preset -M default ctrl-x fish_vi_dec 594 595# 596# visual mode 597# 598bind --preset -M visual h backward-char 599bind --preset -M visual l forward-char 600 601bind --preset -M visual k up-line 602bind --preset -M visual j down-line 603 604bind --preset -M visual b backward-word 605bind --preset -M visual B backward-bigword 606bind --preset -M visual g,e backward-word-end 607bind --preset -M visual g,E backward-bigword-end 608bind --preset -M visual w forward-word-vi 609bind --preset -M visual W forward-bigword-vi 610bind --preset -M visual e forward-word-end 611bind --preset -M visual E forward-bigword-end 612bind --preset -M visual o swap-selection-start-stop repaint-mode 613 614bind --preset -M visual % jump-to-matching-bracket 615bind --preset -M visual f forward-jump 616bind --preset -M visual t forward-jump-till 617bind --preset -M visual F backward-jump 618bind --preset -M visual T backward-jump-till 619bind --preset -M visual';' repeat-jump 620bind --preset -M visual , repeat-jump-reverse 621 622for keyin $eol_keys 623bind --preset -M visual$key end-of-line 624end 625for keyin $bol_keys 626bind --preset -M visual$key beginning-of-line 627end 628 629bind --preset -M visual -m default v end-selection repaint-mode 630bind --preset -M visual -m insert i end-selection repaint-mode 631bind --preset -M visual -m insert I end-selection beginning-of-line repaint-mode 632bind --preset -M visual -m insert c kill-selection end-selection repaint-mode 633bind --preset -M visual -m insert s kill-selection end-selection repaint-mode 634bind --preset -M visual -m default d kill-selection end-selection backward-char repaint-mode 635bind --preset -M visual -m default x kill-selection end-selection repaint-mode 636bind --preset -M visual -m default X kill-whole-line end-selection repaint-mode 637bind --preset -M visual -m default y fish_vi_yank_selection end-selection repaint-mode 638bind --preset -M visual -m default'",*,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" 639bind --preset -M visual -m default'",+,y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" 640bind --preset -M visual -m default\~ togglecase-selection end-selection repaint-mode 641bind --preset -M visual -m default g,u downcase-selection end-selection repaint-mode 642bind --preset -M visual -m default g,U upcase-selection end-selection repaint-mode 643 644bind --preset -M visual -m default ctrl-c end-selection repaint-mode 645bind --preset -M visual -m default escape end-selection repaint-mode 646bind --preset -M visual -m default ctrl-\[ end-selection repaint-mode 647 648# Make it easy to turn an unexecuted command into a comment in the shell history. Also, remove 649# the commenting chars so the command can be further edited then executed. 650bind --preset -M default\# __fish_toggle_comment_commandline 651bind --preset -M visual\# __fish_toggle_comment_commandline 652bind --preset -M replace\# __fish_toggle_comment_commandline 653 654# Set the cursor shape 655# After executing once, this will have defined functions listening for the variable. 656# Therefore it needs to be before setting fish_bind_mode. 657fish_vi_cursor 658set -g fish_cursor_selection_mode inclusive 659function __fish_vi_key_bindings_on_mode_change --on-variable fish_bind_mode 660switch $fish_bind_mode 661case insert replace 662set -g fish_cursor_end_mode exclusive 663case '*' 664set -g fish_cursor_end_mode inclusive 665end 666end 667function __fish_vi_key_bindings_remove_handlers --on-variable __fish_active_key_bindings 668functions --erase __fish_vi_key_bindings_remove_handlers 669functions --erase __fish_vi_key_bindings_on_mode_change 670if type -q __fish_vi_cursor 671__fish_vi_cursor fish_cursor_default 672end 673functions --erase fish_vi_cursor_handle 674functions --erase fish_vi_cursor_handle_preexec 675set -e -g fish_cursor_end_mode 676set -e -g fish_cursor_selection_mode 677end 678 679set fish_bind_mode$init_mode 680end