Skip to content

fish_vi_key_bindings: add support for count - #12170

Closed
HeitorAugustoLN wants to merge 1 commit into
fish-shell:masterfrom
HeitorAugustoLN:vcount
Closed

fish_vi_key_bindings: add support for count#12170
HeitorAugustoLN wants to merge 1 commit into
fish-shell:masterfrom
HeitorAugustoLN:vcount

Conversation

@HeitorAugustoLN

@HeitorAugustoLN HeitorAugustoLN commented Dec 16, 2025

Copy link
Copy Markdown
Contributor

Description

Adds support for v:count in vi keybinds, also added functions for simplifying e/E definitions.
Adds a new operator mode for handling bindings such as d3w

Fixes issue #2192

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@HeitorAugustoLN
HeitorAugustoLN force-pushed the vcount branch 2 times, most recently from 8a80861 to b93b604 Compare December 16, 2025 17:28
Comment thread share/functions/fish_vi_key_bindings.fish Outdated
Comment thread share/functions/fish_vi_key_bindings.fish
Comment thread share/functions/fish_vi_key_bindings.fish
@krobelus

Copy link
Copy Markdown
Contributor

probably worth a brief mention in the changelog

@HeitorAugustoLN
HeitorAugustoLN force-pushed the vcount branch 2 times, most recently from c3da561 to 97049e1 Compare December 20, 2025 12:11
@HeitorAugustoLN

HeitorAugustoLN commented Dec 20, 2025

Copy link
Copy Markdown
Contributor Author

I had to make an operator mode, similarly to vim, because otherwise, motions like 3dw or d3w wouldn't work

@HeitorAugustoLN
HeitorAugustoLN force-pushed the vcount branch 3 times, most recently from 62296db to 0008fa7 Compare December 20, 2025 12:26
@krobelus krobelus added this to the fish 4.3 milestone Dec 21, 2025
set -g __fish_vi_start_count $__fish_vi_count
set -g __fish_vi_count
set fish_bind_mode operator
commandline -f repaint-mode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice, the operator mode seems like the correct thing to do.

Typing "d2" with the default config shows that the default
fish_mode_prompt is empty.
Can you update that?
Searching for case replace_one finds three occurrences.

Maybe we should display the operator in context, so 'd' or 'c'
(but it should always be width one, to avoid jumping)

It also looks like typing only "d" does not repaint the mode?
Not sure what's up with that.

@HeitorAugustoLN HeitorAugustoLN Dec 21, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Apparently for the mode to update, we need to have at least 3 inputs, and then it will update on the second, and when it's finished it will go back to normal.

For example dge or d2w makes it update the mode. But not 2dw for example

Comment thread share/functions/fish_vi_key_bindings.fish Outdated
set fish_bind_mode insert
case yank
for i in (seq $total)
commandline -f kill-whole-line yank

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to copy everything, only the last line (unless I tested wrong).
If we can't fix that we should at least acknowledge it with a TODO comment.

Comment thread share/functions/fish_vi_key_bindings.fish Outdated
bind -s --preset -M default d 'fish_vi_start_operator delete'
bind -s --preset -M default c 'fish_vi_start_operator change'
bind -s --preset -M default y 'fish_vi_start_operator yank'
bind -s --preset -M default \~ 'fish_vi_start_operator swap-case'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In future, we can add some more operators (as listed in Vim's :h operator) like gu/gU

bind -s --preset -M default \~ 'fish_vi_start_operator swap-case'

bind -s --preset -M operator escape fish_vi_operator_cancel
bind -s --preset -M operator ctrl-\[ fish_vi_operator_cancel

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(unrelated) our ctrl-c behavior is weirdly different from Vim; not sure if that's good

bind -s --preset d,B backward-kill-bigword
bind -s --preset d,g,e backward-kill-word
bind -s --preset d,g,E backward-kill-bigword
bind -s --preset d,f begin-selection forward-jump kill-selection end-selection

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't review whether the set of binds is equivalent because they were moved.
If we want it to be easy to see if anything has been dropped or wrongly added, we should

  1. start with a commit that only moves lines, without other changes
  2. then add another commit that only replaces lines with new operations, and doesn't move them

but that's not necessary, just some food for thought

@krobelus

Copy link
Copy Markdown
Contributor

since you didn't make any manual changes to po/ you can do git checkout --ours -- po or jj resolve --tool=:ours po/ when you hit the conflict while rebasing (and then regenerate translations)

@HeitorAugustoLN
HeitorAugustoLN force-pushed the vcount branch 3 times, most recently from eb41fb6 to 5d9a221 Compare December 21, 2025 14:49
Comment thread share/functions/fish_default_mode_prompt.fish
Comment thread share/functions/fish_vi_key_bindings.fish Outdated
Comment thread share/functions/fish_vi_key_bindings.fish Outdated
Comment thread share/functions/fish_vi_key_bindings.fish Outdated
@krobelus krobelus modified the milestones: fish-future, fish 4.4 Jan 11, 2026
@krobelus krobelus closed this in 38e633d Jan 11, 2026
@HeitorAugustoLN
HeitorAugustoLN deleted the vcount branch January 11, 2026 22:15
@zanchey zanchey linked an issue Jan 12, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vi mode: '<count>s' doesn't work.

2 participants