mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 20:31:19 -03:00
feat(vi-mode): make word movements vi-compliant
- The behavior of `{,d}{w,W}`, `{,d}{,g}{e,E}` bindings in vi-mode is
now more compatible with vim, except that the underscore is not a
keyword (which can be achieved by setting `set iskeyword-=_` in vim).
- Add commands `{forward,kill}-{word,bigword}-vi`,
`{forward,backward,kill,backward-kill}-{word,bigword}-end` and
`kill-{a,inner}-{word,bigword}` corresponding to above-mentioned
bindings.
- Closes #10393.
Closes #12269
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
This commit is contained in:
committed by
Johannes Altmanninger
parent
4c3fcc7b16
commit
bbb2f0de8d
@@ -131,18 +131,12 @@ The following special input functions are available:
|
||||
move one character to the left, but do not trigger any non-movement-related operations. If the cursor is at the start of
|
||||
the commandline, does nothing. Does not change the selected item in the completion pager UI when shown.
|
||||
|
||||
``backward-bigword``
|
||||
move one whitespace-delimited word to the left
|
||||
|
||||
``backward-token``
|
||||
move one argument to the left
|
||||
|
||||
``backward-delete-char``
|
||||
deletes one character of input to the left of the cursor
|
||||
|
||||
``backward-kill-bigword``
|
||||
move the whitespace-delimited word to the left of the cursor to the killring
|
||||
|
||||
``backward-kill-token``
|
||||
move the argument to the left of the cursor to the killring
|
||||
|
||||
@@ -155,13 +149,31 @@ The following special input functions are available:
|
||||
move one path component to the left of the cursor to the killring. A path component is everything likely to belong to a path component, i.e. not any of the following: `/={,}'\":@ |;<>&`, plus newlines and tabs.
|
||||
|
||||
``backward-kill-word``
|
||||
move the word to the left of the cursor to the killring. The "word" here is everything up to punctuation or whitespace.
|
||||
move the word to the left of the cursor to the killring, until the start of the current word (like vim's ``db``)
|
||||
|
||||
``backward-kill-bigword``
|
||||
move the whitespace-delimited word to the left of the cursor to the killring, until the start of the current word (like vim's ``dB``)
|
||||
|
||||
``backward-kill-word-end``
|
||||
move from the cursor to the end of the previous word to the killring (like vim's ``dge``)
|
||||
|
||||
``backward-kill-bigword-end``
|
||||
move from the cursor to the end of the previous whitespace-delimited word to the killring (like vim's ``dgE``)
|
||||
|
||||
``backward-path-component``
|
||||
move one :ref:`path component <cmd-bind-backward-kill-path-component>` to the left.
|
||||
move one :ref:`path component <cmd-bind-backward-kill-path-component>` to the left
|
||||
|
||||
``backward-word``
|
||||
move one word to the left
|
||||
move one word to the left, stopping at the start of the previous word (like vim's ``b``, or Emacs' ``M-b`` but differs slightly in word division rules)
|
||||
|
||||
``backward-bigword``
|
||||
move one whitespace-delimited word to the left, stopping at the start of the previous word (like vim's ``B``)
|
||||
|
||||
``backward-word-end``
|
||||
move to the end of the previous word (like vim's ``ge``)
|
||||
|
||||
``backward-bigword-end``
|
||||
move to the end of the previous whitespace-delimited word (like vim's ``gE``)
|
||||
|
||||
``beginning-of-buffer``
|
||||
moves to the beginning of the buffer, i.e. the start of the first line
|
||||
@@ -236,9 +248,6 @@ The following special input functions are available:
|
||||
``exit``
|
||||
exit the shell
|
||||
|
||||
``forward-bigword``
|
||||
move one whitespace-delimited word to the right
|
||||
|
||||
``forward-token``
|
||||
move one argument to the right
|
||||
|
||||
@@ -257,10 +266,29 @@ The following special input functions are available:
|
||||
``forward-single-char``
|
||||
move one character to the right; or if at the end of the commandline, accept a single char from the current autosuggestion.
|
||||
|
||||
.. _cmd-bind-forward-word:
|
||||
|
||||
``forward-word``
|
||||
move one word to the right; or if at the end of the commandline, accept one word
|
||||
move one word to the right, stopping after the end of the current word; or if at the end of the commandline, accept one word
|
||||
from the current autosuggestion.
|
||||
|
||||
``forward-word-vi``
|
||||
like :ref:`forward-word <cmd-bind-forward-word>`, but stops at the start of the next word (like vim's ``w``)
|
||||
|
||||
``forward-word-end``
|
||||
like :ref:`forward-word <cmd-bind-forward-word>`, but stops at the end of the next word (like vim's ``e``)
|
||||
|
||||
.. _cmd-bind-forward-bigword:
|
||||
|
||||
``forward-bigword``
|
||||
move one whitespace-delimited word to the right, stopping after the end of the current word; or if at the end of the commandline, accept one word from the current autosuggestion.
|
||||
|
||||
``forward-bigword-vi``
|
||||
like :ref:`forward-bigword <cmd-bind-forward-bigword>`, but stops at the start of the next word (like vim's ``W``)
|
||||
|
||||
``forward-bigword-end``
|
||||
like :ref:`forward-bigword <cmd-bind-forward-bigword>`, but stops at the end of the next word (like vim's ``E``)
|
||||
|
||||
``history-pager``
|
||||
invoke the searchable pager on history (incremental search); or if the history pager is already active, search further backwards in time.
|
||||
|
||||
@@ -312,9 +340,6 @@ The following special input functions are available:
|
||||
The input function is useful to emulate ``ib`` vi text object.
|
||||
The following brackets are considered: ``([{}])``
|
||||
|
||||
``kill-bigword``
|
||||
move the next whitespace-delimited word to the killring
|
||||
|
||||
``kill-token``
|
||||
move the next argument to the killring
|
||||
|
||||
@@ -334,7 +359,34 @@ The following special input functions are available:
|
||||
move the line (without the following newline) to the killring
|
||||
|
||||
``kill-word``
|
||||
move the next word to the killring
|
||||
move the next word to the killring, stopping after the end of the killed word
|
||||
|
||||
``kill-word-vi``
|
||||
move the next word to the killring, stopping at the start of the next word (like vim's ``dw``)
|
||||
|
||||
``kill-bigword``
|
||||
move the next whitespace-delimited word to the killring, stopping after the end of the current word
|
||||
|
||||
``kill-bigword-vi``
|
||||
move the next whitespace-delimited word to the killring, stopping at the start of the next word (like vim's ``dW``)
|
||||
|
||||
``kill-bigword-end``
|
||||
move from the cursor to the end of the current whitespace-delimited word to the killring (like vim's ``dE``)
|
||||
|
||||
``kill-word-end``
|
||||
move from the cursor to the end of the current word to the killring (like vim's ``de``)
|
||||
|
||||
``kill-inner-word``
|
||||
delete the word under the cursor (like vim's ``diw``)
|
||||
|
||||
``kill-inner-bigword``
|
||||
delete the whitespace-delimited word under the cursor (like vim's ``diW``)
|
||||
|
||||
``kill-a-word``
|
||||
delete the word under the cursor plus surrounding whitespace (like vim's ``daw``)
|
||||
|
||||
``kill-a-bigword``
|
||||
delete the whitespace-delimited word under the cursor plus surrounding whitespace (like vim's ``daW``)
|
||||
|
||||
``nextd-or-forward-word``
|
||||
if the commandline is empty, then move forward in the directory history, otherwise move one word to the right;
|
||||
|
||||
@@ -24,6 +24,19 @@ The following parameters are available:
|
||||
|
||||
Further information on how to use :ref:`vi mode <vi-mode>`.
|
||||
|
||||
Differences from Vim
|
||||
--------------------
|
||||
|
||||
Fish's vi mode aims to be familiar to vim users, but there are some differences:
|
||||
|
||||
**Word character handling**
|
||||
In vim, underscore (``_``) is treated as a keyword character by default, so word motions like ``w``, ``b``, and ``e`` treat ``foo_bar`` as a single word. In fish, underscore is treated as punctuation, so word motions stop at underscores. For example, pressing ``w`` on ``foo_bar`` in fish stops at the ``_``, while in vim it would jump past the entire identifier.
|
||||
|
||||
**The** ``cw`` **command**
|
||||
In vim, ``cw`` has special behavior: when the cursor is on a non-space character, it behaves like ``ce`` (change to end of word), but when the cursor is on a space, it behaves like ``dwi`` (delete word then insert).
|
||||
|
||||
In fish, ``cw`` always behaves like ``dwi`` - it deletes to the start of the next word (including trailing whitespace), then enters insert mode. To get vim's ``cw`` behavior in fish, use ``ce`` instead.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user