set -l init_mode insert if contains -- $argv[1] insert default visual set init_mode $argv[1] else if set -q argv[1] # We should still go on so the bindings still get set. echo "Unknown argument $argv" >&2 end # Inherit shared key bindings. # Do this first so vi-bindings win over default. for mode in insert default visual __fish_shared_key_bindings -s -M $mode end # Add a way to switch from insert to normal (command) mode. # Note if we are paging, we want to stay in insert mode # See #2871 bind -s --preset -M insert \e "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end" # Default (command) mode bind -s --preset :q exit bind -s --preset -m insert \cc cancel-commandline repaint-mode bind -s --preset -M default h backward-char bind -s --preset -M default l forward-char bind -s --preset -M visual h begin-selection backward-char bind -s --preset -M visual l begin-selection forward-char bind -s --preset -m insert \n execute bind -s --preset -m insert \r execute bind -s --preset -m insert o insert-line-under repaint-mode bind -s --preset -m insert O insert-line-over repaint-mode bind -s --preset -m insert i repaint-mode bind -s --preset -m insert I beginning-of-line repaint-mode bind -s --preset -m insert a forward-single-char repaint-mode bind -s --preset -m insert A end-of-line repaint-mode # Selection keys (if in default mode) bind -s --preset -M default -m visual H begin-selection backward-char bind -s --preset -M default -m visual L begin-selection forward-char bind -s --preset -M default -m visual J begin-selection down-or-search bind -s --preset -M default -m visual K begin-selection up-or-search bind -s --preset -M default -m visual x beginning-of-line begin-selection end-of-line # TODO: Implement x when already in visual mode # (if already in visual mode) bind -s --preset -M visual H backward-char bind -s --preset -M visual L forward-char bind -s --preset -M visual J backward-char bind -s --preset -M visual K backward-char # Goto keys bind -s --preset gh end-selection beginning-of-line bind -s --preset gj end-selection end-of-buffer bind -s --preset gk end-selection beginning-of-buffer bind -s --preset gl end-selection end-of-line bind -s --preset gg end-selection beginning-of-buffer # (Goto+Selection) keys bind -s --preset -M default -m visual gH begin-selection beginning-of-line bind -s --preset -M default -m visual gJ begin-selection end-of-buffer bind -s --preset -M default -m visual gK begin-selection beginning-of-buffer bind -s --preset -M default -m visual gL begin-selection end-of-line bind -s --preset -M visual gH beginning-of-line bind -s --preset -M visual gJ end-of-buffer bind -s --preset -M visual gK beginning-of-buffer bind -s --preset -M visual gL end-of-line # Undo keys bind -s --preset u undo bind -s --preset U redo # History navigation bind -s --preset / history-pager --sets-mode insert repaint bind -s --preset k up-or-search bind -s --preset j down-or-search bind -s --preset b -m visual backward-word bind -s --preset B -m visual backward-bigword bind -s --preset w -m visual forward-word forward-single-char bind -s --preset W -m visual forward-bigword forward-single-char # Backspace deletes a char in insert mode bind -s --preset -M insert -k backspace backward-delete-char bind -s --preset -M insert \ch backward-delete-char bind -s --preset -M insert \x7f backward-delete-char bind -s --preset -M visual d kill-selection bind -s --preset '~' togglecase-char forward-single-char bind -s --preset gu downcase-word bind -s --preset gU 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 y yank-selection bind -s --preset -m normal -M visual f forward-jump bind -s --preset -m normal -M visual t forward-jump-till bind -s --preset -m normal -M visual F backward-jump bind -s --preset -m normal -M visual T backward-jump-till bind -s --preset p forward-char yank bind -s --preset P yank bind -s --preset gp yank-pop # same vim 'pasting' note as upper bind -s --preset '"*p' forward-char "commandline -i ( xsel -p; echo )[1]" bind -s --preset '"*P' "commandline -i ( xsel -p; echo )[1]" # # Lowercase r, enters replace_one mode # bind -s --preset -m replace_one r repaint-mode bind -s --preset -M replace_one -m default '' delete-char self-insert backward-char repaint-mode bind -s --preset -M replace_one -m default \r 'commandline -f delete-char; commandline -i \n; commandline -f backward-char; commandline -f repaint-mode' bind -s --preset -M replace_one -m default \e cancel repaint-mode # # Uppercase R, enters replace mode # bind -s --preset -m replace R repaint-mode bind -s --preset -M replace '' delete-char self-insert bind -s --preset -M replace -m insert \r execute repaint-mode bind -s --preset -M replace -m default \e cancel repaint-mode bind -s --preset -M visual -m insert c kill-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 \cc end-selection repaint-mode bind -s --preset -M visual -m default \e end-selection repaint-mode # Make it easy to turn an unexecuted command into a comment in the shell history. Also, remove # the commenting chars so the command can be further edited then executed. bind -s --preset -M default \# __fish_toggle_comment_commandline bind -s --preset -M visual \# __fish_toggle_comment_commandline bind -s --preset -M replace \# __fish_toggle_comment_commandline # Set the cursor shape # After executing once, this will have defined functions listening for the variable. # Therefore it needs to be before setting fish_bind_mode. set -g fish_vi_cursor inclusive set -g fish_cursor_selection_mode inclusive set fish_bind_mode $init_mode