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

Feature request: Add a way to replace every instance of a substring on the current line #231

Open
Hubro opened this issue Jul 12, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Hubro
Copy link
Sponsor

Hubro commented Jul 12, 2023

(This is not a bug report, so I'm not following the standard template)

First of all, let me say that zsh-vi-mode is amazing, I'm certain it's the best Vi-mode plugin for any shell that exists.

However I have encountered one pretty common scenario that I would easily be able to resolve inside Vim, but is more challenging in zsh-vi-mode.

If I have a line like:

ln -sf ../syncthing/dotfiles/darkman .config/darkman

If I wanted to replace "darkman" with "direnv", in Vim I would just place my cursor on the word "darkman", press <C-n><C-n> to select both instances of "darkman", then press c to replace the word and enter insert mode, then type "direnv". Super quick and easy. (Though, to be clear, this is using the vim-visual-multi plugin, this is not built-in Vim functionality.)

Without multiple selections, this becomes a lot more tedious, especially when I have to repeat it a bunch of times for several different symlinks.


To summarize the feature request:

Problem: Replacing many instances of the same text on a line is tedious

Solution in Vim/Neovim: A multi-select plugin

Solution in zsh-vi-mode: ?

Possible solutions:

  • Add multiple cursors to zsh-vi-mode (drawback: extremely complicated)
  • Add limited support for multiple selections
    • Make a visual selection, then press a keybinding to also select the next instance of the selected text
    • Also needs a keybinding to skip the current selection and jump to the next one
    • Allow pressing d or x to delete the selection and leave multi-select mode, or press c to replace the selections and insert some new text, I to enter insert mode at the start of every selection or A to enter insert mode at the end of every selection
    • Simpler than full-blown multi-cursor mode, still massively powerful
  • Add a "replace all" keybinding
    • The user selects a span of text
    • Presses a keybinding called something "replace all"
    • This deletes the selected text and enters insert mode
    • When leaving insert mode, all the other instances of the selected text on the same line is also replaced
    • Much, much simpler than the above solutions, still solves the issue
@jeffreytse jeffreytse self-assigned this Jul 12, 2023
@jeffreytse jeffreytse added the enhancement New feature or request label Jul 12, 2023
@jeffreytse
Copy link
Owner

Hi @Hubro,

Thank you very much for your good idea and scenarios, I'd love to explore this feature in the next days.

Thanks & Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants