Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill pure Vi key bindings, use hybrid behavior instead #10339

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions doc_src/interactive.rst
Expand Up @@ -277,14 +277,11 @@ The fish editor features copy and paste, a :ref:`searchable history <history-sea
Like bash and other shells, fish includes two sets of keyboard shortcuts (or key bindings): one inspired by the Emacs text editor, and one by the vi text editor. The default editing mode is Emacs. You can switch to vi mode by running :doc:`fish_vi_key_bindings <cmds/fish_vi_key_bindings>` and switch back with :doc:`fish_default_key_bindings <cmds/fish_default_key_bindings>`. You can also make your own key bindings by creating a function and setting the ``fish_key_bindings`` variable to its name. For example::


function fish_hybrid_key_bindings --description \
"Vi-style bindings that inherit emacs-style bindings in all modes"
for mode in default insert visual
fish_default_key_bindings -M $mode
end
fish_vi_key_bindings --no-erase
function my_key_bindings
fish_default_key_bindings_key_bindings # or fish_vi_key_bindings
bind \cg beginning-of-line 'commandline -i "# "'
end
set -g fish_key_bindings fish_hybrid_key_bindings
set -g fish_key_bindings my_key_bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not tell people to make a full function to change a single binding.

We still have people define fish_user_key_bindings because they read older docs or blog posts, and this adds to the confusion.


While the key bindings included with fish include many of the shortcuts popular from the respective text editors, they are not a complete implementation. They include a shortcut to open the current command line in your preferred editor (:kbd:`Alt`\ +\ :kbd:`E` by default) if you need the full power of your editor.

Expand Down
19 changes: 2 additions & 17 deletions share/functions/fish_hybrid_key_bindings.fish
@@ -1,18 +1,3 @@
function fish_hybrid_key_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes"
bind --erase --all --preset # clear earlier bindings, if any

if test "$fish_key_bindings" != fish_hybrid_key_bindings
# Allow the user to set the variable universally
set -q fish_key_bindings
or set -g fish_key_bindings
# This triggers the handler, which calls us again and ensures the user_key_bindings
# are executed.
set fish_key_bindings fish_hybrid_key_bindings
return
end

for mode in default insert visual
fish_default_key_bindings -M $mode
end
fish_vi_key_bindings --no-erase
function fish_hybrid_key_bindings --description "Deprecated, use fish_vi_key_bindings"
fish_vi_key_bindings fish_hybrid_key_bindings
end
23 changes: 22 additions & 1 deletion share/functions/fish_vi_key_bindings.fish
@@ -1,4 +1,25 @@
function fish_vi_key_bindings --description 'vi-like key bindings for fish'
function fish_vi_key_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes"
set -l bindings_name $argv[1] fish_vi_key_bindings

bind --erase --all --preset # clear earlier bindings, if any

if test "$fish_key_bindings" != $bindings_name[1]
# Allow the user to set the variable universally
set -q fish_key_bindings
or set -g fish_key_bindings
# This triggers the handler, which calls us again and ensures the user_key_bindings
# are executed.
set fish_key_bindings $bindings_name[1]
return
end

for mode in default insert visual
fish_default_key_bindings -M $mode
end
__fish_vi_key_bindings --no-erase
end

function __fish_vi_key_bindings --description 'vi-like key bindings for fish'
if contains -- -h $argv
or contains -- --help $argv
echo "Sorry but this function doesn't support -h or --help" >&2
Expand Down
1 change: 0 additions & 1 deletion share/tools/web_config/sample_prompts/nim.fish
Expand Up @@ -84,7 +84,6 @@ function fish_prompt
end

if test "$fish_key_bindings" = fish_vi_key_bindings
or test "$fish_key_bindings" = fish_hybrid_key_bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did merge this, this line should stay, because people will keep using their old hybrid_key_bindings.

set -l mode
switch $fish_bind_mode
case default
Expand Down