Search code examples
shellfish

Ctrl-F no longer works to accept suggestions. Why?


I recently enabled Vi mode by adding fish_vi_mode to my config. Since I did this Ctrl+F no longer works to complete suggestions, I have to use Right Arrow instead.

The keybindings for forward-char are the same with or without fish_vi_mode enabled. According to fish_config, they are:

forward-char    Right Arrow
forward-char    Right Arrow
forward-char    CTRL - f

Why doesn't Ctrl+F work with fish_vi_mode enabled?


Solution

  • In vi mode, run bind and look for \cf, it's here:

    bind -M insert \cf forward-word
    

    that's what's going on: control-F is going forward by a word. You can restore the non-vi behavior:

    bind -M insert \cf forward-char
    

    which is to go forward by one character, or accept the autosuggestion if the cursor is at the end (which is admittedly sort of weird).

    Or if you want it to only accept the autosuggestion, you can run this after fish_vi_mode:

    bind -M insert \cf accept-autosuggestion
    

    Now it accepts the autosuggestion at any point, not just at the end.

    BTW, these functions like accept-autosuggestion or forward-char can be listed via bind --function-names

    Edit: this is harder than it ought to be due to #2254. The simplest thing is to put the call to fish_vi_mode in the fish_user_key_bindings function:

    function fish_user_key_bindings
        fish_vi_mode
        bind -M insert \cf accept-autosuggestion
        bind \cf accept-autosuggestion
    end
    

    You can use funced fish_user_key_bindings to write that function, and then funcsave fish_user_key_bindings to save it.