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

Implement a more user-friendly "literal replace" functionality #2963

Open
friendly-bits opened this issue Oct 13, 2023 · 4 comments
Open

Implement a more user-friendly "literal replace" functionality #2963

friendly-bits opened this issue Oct 13, 2023 · 4 comments

Comments

@friendly-bits
Copy link

friendly-bits commented Oct 13, 2023

Description of the problem or steps to reproduce

This is a feature request which naturally grows out of some reported issues/bugs related to the "replace" functionality. See:
#2951 #2937 #2887 #2832 #2174 #2155 #1920
(I'm not sure if some of the older issues have been partially or fully resolved by now but the issues are still technically open)

Basically the request is to implement:

  1. A way to have literal replace that is actually literal, a.k.a not interpreting absolutely anything, including spaces, backslashes, quotation marks, "$" and other special symbols. You just enter whatever arbitrary string you want to replace, enter another arbitrary string to replace with, and get it done.
  2. Probably implement a better UI for that which should feature separate fields for "string-to-replace" and "replacement-string" (see the rationale in my comment in the discussion inside Literal Replace command works incorrectly when the replacement string contains '$' #2951).
  3. [if not too much work ] As a part of that UI, implement a simple switch for regex or literal mode (maybe toggle by pressing a specific key)
  4. As a part of that UI, implement a button for "replace all" (maybe activate by pressing a specific key)
  5. [ if not too much work ] implement a switch to toggle case-sensitive (or not) search/replace
  6. Consider setting literal replace as the default since (my personal opinion) literal replace is used much more frequently by most users.
  7. Possibly combine the replace UI with the "Find" UI so it's easy to do a task like find all instances of a string in a file, [possibly tweak the string to match exactly what you need to], switch to "replace" mode and replace all instances in one go, without having to re-enter the string again (would be a nice perk but not life-changing). See for example Notepad++ implementation (although that's GUI of course but I don't see why something equivalent, while limited to the above-mentioned features, can't be implemented in a text-based UI, at least the way it's done in Nano for example).

(1) which, as I think, requires (2), is the essential part, at least for me, although each of the other parts will definitely help if possible to implement.

Commit hash: c2cebaa
OS: Debian
Terminal: xterm

@dmaluka
Copy link
Collaborator

dmaluka commented Mar 18, 2024

A way to have literal replace that is actually literal, a.k.a not interpreting absolutely anything, including spaces, backslashes, quotation marks, "$" and other special symbols. You just enter whatever arbitrary string you want to replace, enter another arbitrary string to replace with, and get it done.

This is more or less exactly what Find (Ctrl-f) and FindLiteral (Alt-Shift-f) already do. Instead of the command line (with all its headache of escaping, single and double quotes and so on), you have a prompt where you type just the searched string (regex or literal) and nothing more. It seems like a good idea to implement the same for replace, e.g. Replace and ReplaceLiteral actions, with some default keybindings for them. (Unlike Find, they would have 2 prompts, one after another: for the search string and for the replace string.)

Consider setting literal replace as the default since (my personal opinion) literal replace is used much more frequently by most users.

I'm not sure about that. We don't know how many users prefer using regex replace. We don't hear them complaining about regex replace not being the default, just because, well, it is the default. https://en.wikipedia.org/wiki/Selection_bias

@JoeKar
Copy link
Collaborator

JoeKar commented Mar 18, 2024

It seems like a good idea to implement the same for replace, e.g. Replace and ReplaceLiteral actions, with some default keybindings for them. (Unlike Find, they would have 2 prompts, one after another: for the search string and for the replace string.)

Maybe 3 stages to add additional modes? Speaking for myself I usually like to define within the replace step if it shall be done with ignorecase or not.

@dmaluka
Copy link
Collaborator

dmaluka commented Mar 18, 2024

Maybe 3 stages to add additional modes? Speaking for myself I usually like to define within the replace step if it shall be done with ignorecase or not.

I wouldn't enjoy going through this extra step every time.

@JoeKar
Copy link
Collaborator

JoeKar commented Mar 18, 2024

And I wouldn't like to use set ignorecase true|false or toggle ignorecase every time before I use replace.
In that moment I feel more comfortable with the current approach and allowing me to add -i or not to reach what I want.

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

No branches or pull requests

3 participants