grace/dots
dotfiles/nix configs
git clone https://git.gae.moe/grace/dots
9c3d491
main
1# IMPORTANT!!! 2# 3# When defining your own bindings using fish_helix_command, be aware that it can break 4# stuff sometimes. 5# 6# It is safe to define a binding consisting of a lone call to fish_helix_command. 7# Calls to other functions and executables are allowed along with it, granted they don't mess 8# with fish's commandline buffer. 9# 10# Mixing multiple fish_helix_commandline and commandline calls in one binding MAY trigger issues. 11# Nothing serious, but don't be surprised. Just test it. 12 13function fish_helix_key_bindings--description 'helix-like key bindings for fish' 14if contains ---h $argv 15or contains ----help $argv 16echo "Sorry but this function doesn't support -h or --help" 17return 1 18end 19 20# Erase all bindings if not explicitly requested otherwise to 21# allow for hybrid bindings. 22# This needs to be checked here because if we are called again 23# via the variable handler the argument will be gone. 24set -l rebind true 25if test " $argv [ 1 ] " =--no-erase 26set rebind false 27set -e argv[1] 28else 29bind --erase --all --preset # clear earlier bindings, if any 30end 31 32# Allow just calling this function to correctly set the bindings. 33# Because it's a rather discoverable name, users will execute it 34# and without this would then have subtly broken bindings. 35if test " $fish_key_bindings " != fish_helix_key_bindings 36and test " $rebind " = true 37# Allow the user to set the variable universally. 38set -q fish_key_bindings 39or set -g fish_key_bindings 40# This triggers the handler, which calls us again and ensures the user_key_bindings 41# are executed. 42set fish_key_bindings fish_helix_key_bindings 43return 44end 45 46set -l init_mode insert 47 48if contains --$argv [ 1 ] insert default visual 49set init_mode$argv [ 1 ] 50else if set -q argv[1] 51# We should still go on so the bindings still get set. 52echo "Unknown argument $argv " >&2 53end 54 55function __fish_helix_key_bindings_shared 56eval " $( __fish_shared_key_bindings ) " 57end 58 59# Inherit shared key bindings. 60# Do this first so helix-bindings win over default. 61for modein insert default visual 62__fish_helix_key_bindings_shared -M $mode 63end 64functions -e __fish_helix_key_bindings_shared 65 66bind -s --preset -M insert\r execute 67bind -s --preset -M insert\n execute 68 69bind -s --preset -M insert"" self-insert 70 71# Space and other command terminators expand abbrs _and_ inserts itself. 72bind -s --preset -M insert" " self-insert expand-abbr 73bind -s --preset -M insert";" self-insert expand-abbr 74bind -s --preset -M insert"|" self-insert expand-abbr 75bind -s --preset -M insert"&" self-insert expand-abbr 76bind -s --preset -M insert"^" self-insert expand-abbr 77bind -s --preset -M insert">" self-insert expand-abbr 78bind -s --preset -M insert"<" self-insert expand-abbr 79# Closing a command substitution expands abbreviations 80bind -s --preset -M insert")" self-insert expand-abbr 81# Ctrl-space inserts space without expanding abbrs 82bind -s --preset -M insert ctrl-space'commandline -i " "' 83 84# Switching to insert mode 85for modein default visual 86bind -s --preset -M $mode -m insert\c c end-selection cancel-commandline repaint-mode 87bind -s --preset -M $mode -m insert\n end-selection execute 88bind -s --preset -M $mode -m insert\r end-selection execute 89bind -s --preset -M $mode -m insert o end-selection insert-line-under repaint-mode 90bind -s --preset -M $mode -m insert O end-selection insert-line-over repaint-mode 91# FIXME i/a should keep selection, maybe 92bind -s --preset -M $mode i"fish_helix_command insert_mode" 93bind -s --preset -M $mode I"fish_helix_command prepend_to_line" 94bind -s --preset -M $mode a"fish_helix_command append_mode" 95bind -s --preset -M $mode A"fish_helix_command append_to_line" 96end 97 98# Switching from insert mode 99# Note if we are paging, we want to stay in insert mode 100# See #2871 101bind -s --preset -M insert\e "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f begin-selection repaint-mode; end" 102 103# Switching between normal and visual mode 104bind -s --preset -M default-m visual v repaint-mode 105for keyin v\e 106bind -s --preset -M visual-m default$key repaint-mode 107end 108 109# Motion and actions in normal/select mode 110for modein default visual 111if test $mode = default 112set -f n_begin_selection begin-selection# only begin-selection if current mode is Normal 113set -f ns_move_extend move 114set -f commandline_v_repaint"" 115else 116set -f n_begin_selection 117set -f ns_move_extend extend 118set -f commandline_v_repaint"commandline -f repaint-mode" 119end 120 121for keyin ( seq 0 9) 122bind -s --preset -M $mode $key "fish_bind_count $key " 123# FIXME example to bind 0 124# FIXME backspace to edit count 125end 126for keyin h\e\[ D\e OD left 127bind -s --preset -M $mode $key "fish_helix_command " $ns_move_extend "_char_left" 128end 129for keyin l\e\[ C\e OC right 130bind -s --preset -M $mode $key "fish_helix_command " $ns_move_extend "_char_right" 131end 132for keyin k\e\[ A\e OA up 133bind -s --preset -M $mode $key "fish_helix_command char_up" 134end 135for keyin j\e\[ B\e OB down 136bind -s --preset -M $mode $key "fish_helix_command char_down" 137end 138 139bind -s --preset -M $mode w"fish_helix_command next_word_start" 140bind -s --preset -M $mode b"fish_helix_command prev_word_start" 141bind -s --preset -M $mode e"fish_helix_command next_word_end" 142bind -s --preset -M $mode W"fish_helix_command next_long_word_start" 143bind -s --preset -M $mode B"fish_helix_command prev_long_word_start" 144bind -s --preset -M $mode E"fish_helix_command next_long_word_end" 145 146bind -s --preset -M $mode t"fish_helix_command till_next_char" 147bind -s --preset -M $mode f"fish_helix_command find_next_char" 148bind -s --preset -M $mode T"fish_helix_command till_prev_char" 149bind -s --preset -M $mode F"fish_helix_command find_prev_char" 150 151bind -s --preset -M $mode t\e "" 152bind -s --preset -M $mode f\e "" 153bind -s --preset -M $mode T\e "" 154bind -s --preset -M $mode alt-f"" 155 156for enterin \r \n 157bind -s --preset -M $mode "t, $enter " "fish_helix_command till_next_cr" 158bind -s --preset -M $mode "f, $enter " "fish_helix_command find_next_cr" 159bind -s --preset -M $mode "T, $enter " "fish_helix_command till_prev_cr" 160bind -s --preset -M $mode "F, $enter " "fish_helix_command find_prev_cr" 161end 162 163for keyin gh\e\[ H\e OH home 164bind -s --preset -M $mode $key "fish_helix_command goto_line_start" 165end 166for keyin gl\e\[ F\e OF end 167bind -s --preset -M $mode $key "fish_helix_command goto_line_end" 168end 169bind -s --preset -M $mode gs"fish_helix_command goto_first_nonwhitespace" 170bind -s --preset -M $mode gg"fish_helix_command goto_file_start" 171bind -s --preset -M $mode G"fish_helix_command goto_line" 172bind -s --preset -M $mode ge"fish_helix_command goto_last_line" 173 174# FIXME alt-. doesn't work with t/T 175# FIXME alt-. doesn't work with [ftFT][\n\r] 176bind -s --preset -M $mode \e . repeat-jump 177 178# FIXME reselect after undo/redo 179bind -s --preset -M $mode u undo begin-selection 180bind -s --preset -M $mode U redo begin-selection 181 182bind -s --preset -M $mode -m replace_one r repaint-mode 183 184# FIXME registers 185# bind -s --preset -M $mode y fish_clipboard_copy 186# bind -s --preset -M $mode P fish_clipboard_paste 187# bind -s --preset -M $mode R kill-selection begin-selection yank-pop yank 188 189bind -s --preset -M $mode -m default d"fish_helix_command delete_selection; $commandline_v_repaint " 190bind -s --preset -M $mode -m default\e d"fish_helix_command delete_selection_noyank; $commandline_v_repaint " 191bind -s --preset -M $mode -m insert c"fish_helix_command delete_selection; commandline -f end-selection repaint-mode" 192bind -s --preset -M $mode -m insert\e c"fish_helix_command delete_selection_noyank; commandline -f end-selection repaint-mode" 193 194bind -s --preset -M $mode -m default y"fish_helix_command yank" 195bind -s --preset -M $mode p"fish_helix_command paste_after" 196bind -s --preset -M $mode P"fish_helix_command paste_before" 197bind -s --preset -M $mode R"fish_helix_command replace_selection" 198 199bind -s --preset -M $mode -m default" y" "fish_clipboard_copy; $commandline_v_repaint " 200bind -s --preset -M $mode " p" "fish_helix_command paste_after_clip" 201bind -s --preset -M $mode " P" "fish_helix_command paste_before_clip" 202bind -s --preset -M $mode " R" "fish_helix_command replace_selection_clip" 203 204# FIXME keep selection 205bind -s --preset -M $mode '~' togglecase-selection 206# FIXME ` and \e` 207 208# FIXME . 209# FIXME < and > 210# FIXME = 211 212# FIXME \ca \cx 213# FIXME Qq 214 215## Shell 216# FIXME 217 218## Selection manipulation 219# FIXME & _ 220 221bind -s --preset -M $mode \; begin-selection 222bind -s --preset -M $mode \e\; swap-selection-start-stop 223# FIXME \e: 224 225bind -s --preset -M $mode %"fish_helix_command select_all" 226 227bind -s --preset -M $mode x end-selection beginning-of-line begin-selection end-of-line 228# FIXME X \ex 229# FIXME J 230# FIXME \cc 231 232## Search 233# FIXME 234 235## FIXME minor modes: g, m, space 236 237## FIXME [ and ] motions 238end 239 240# FIXME should replace the whole selection 241# FIXME should be able to go back to visual mode 242bind -s --preset -M replace_one-m default'' delete-char self-insert backward-char repaint-mode 243bind -s --preset -M replace_one-m default\r 'commandline -f delete-char; commandline -i \n; commandline -f backward-char; commandline -f repaint-mode' 244bind -s --preset -M replace_one-m default\e cancel repaint-mode 245 246## FIXME Insert mode keys 247 248## Old config from vi: 249 250# Vi moves the cursor back if, after deleting, it is at EOL. 251# To emulate that, move forward, then backward, which will be a NOP 252# if there is something to move forward to. 253bind -s --preset -M insert delete delete-char forward-single-char backward-char 254bind -s --preset -M default delete delete-char forward-single-char backward-char 255 256# Backspace deletes a char in insert mode, but not in normal/default mode. 257bind -s --preset -M insert backspace backward-delete-char 258bind -s --preset -M default backspace backward-char 259bind -s --preset -M insert\c h backward-delete-char 260bind -s --preset -M default\c h backward-char 261bind -s --preset -M insert\x 7f backward-delete-char 262bind -s --preset -M default\x 7f backward-char 263bind -s --preset -M insert shift-delete backward-delete-char# shifted delete 264bind -s --preset -M default shift-delete backward-delete-char# shifted delete 265 266# bind -s --preset '~' togglecase-char forward-single-char 267# bind -s --preset gu downcase-word 268# bind -s --preset gU upcase-word 269# 270# bind -s --preset J end-of-line delete-char 271# bind -s --preset K 'man (commandline -t) 2>/dev/null; or echo -n \a' 272# 273 274# same vim 'pasting' note as upper 275bind -s --preset '"*p' forward-char"commandline -i ( xsel -p; echo )[1]" 276bind -s --preset '"*P' "commandline -i ( xsel -p; echo )[1]" 277 278# 279# visual mode 280# 281 282# bind -s --preset -M visual -m insert c kill-selection end-selection repaint-mode 283# bind -s --preset -M visual -m insert s kill-selection end-selection repaint-mode 284bind -s --preset -M visual-m default'"*y' "fish_clipboard_copy; commandline -f end-selection repaint-mode" 285bind -s --preset -M visual-m default'~' togglecase-selection end-selection repaint-mode 286 287# Set the cursor shape 288# After executing once, this will have defined functions listening for the variable. 289# Therefore it needs to be before setting fish_bind_mode. 290fish_vi_cursor 291set -g fish_cursor_selection_mode inclusive 292 293set fish_bind_mode$init_mode 294 295end