jeffreytse / zsh-vi-mode

💻 A better and friendly vi(vim) mode plugin for ZSH.
MIT License
3.32k stars 113 forks source link

Allow use of registers #279

Open oolonc opened 7 months ago

oolonc commented 7 months ago

Problem description

In the Vi mode built-in to ZSH " is bound to vi-set-buffer in the vicmd map. It would be convenient to be able to store sections of a command into a register to quickly rearrange things. Would it be possible to have this functionality in ZVM?

Expected behavior

According to zshzle(1):

vi-set-buffer (unbound) (") (unbound)

Specify a buffer to be used in the following command. There are 37 buffers that can be specified: the 26 ‘named’ buffers "a to "z, the ‘yank’ buffer "0, the nine ‘queued’ buffers "1 to "9 and the ‘black hole’ buffer "_. The named buffers can also be specified as "A to "Z.

When a buffer is specified for a cut, change or yank command, the text concerned replaces the previous contents of the specified buffer. If a named buffer is specified using a capital, the newly cut text is appended to the buffer instead of overwriting it. When using the "_ buffer, nothing happens. This can be useful for deleting text without affecting any buffers.

If no buffer is specified for a cut or change command, "1 is used, and the contents of "1 to "8 are each shifted along one buffer; the contents of "9 is lost. If no buffer is specified for a yank command, "0 is used. Finally, a paste command without a specified buffer will paste the text from the most recent command regardless of any buffer that might have been used with that command.

When called from a widget function by the zle command, the buffer can optionally be specified with an argument. For example,

zle vi-set-buffer A