Support regex substitution command #8572
Replies: 19 comments
-
For accessing regex matches: #2167 The Helix equivalent for this is to select the buffer ( The only other reason to add a command line this is to be able to map a keybinding to it. With #1383 though you could map a key to the search and replace workflow as well. |
Beta Was this translation helpful? Give feedback.
-
@the-mikedavis Genuinely, thank you for the feedback. I really appreciate the effort to keep Helix as lean as possible and without duplicate workflows. I entirely agree that the mutli-cursor flow is superior to regex replacement in the majority of cases. In my experience there are a couple areas where multi-cursor is either more time consuming or unable to effectively solve a problem:
I am concerned with the feature resulting in bloat when I get around to implementing it. For this reason, I was thinking of simply increasing the expressiveness of the existing substitution and picker dialogs to support standard regex expressions such as I am new to contributing to Helix so I wanted to make sure that this would be a welcome feature and in alignment with the communities goals before I get started on implementation. I would love to know your thoughts @the-mikedavis |
Beta Was this translation helpful? Give feedback.
-
I don't mean to shoot your idea down 😅, it's just that IMO this doesn't belong in the core. I also might be out of touch with what other members think - others may agree this should be implemented within Helix. For those three points I would use a tool built for the task like fastmod (outside of Helix). In other situations, a rename done through LSP Being a refactoring swiss-army-knife is out of scope for the core IMO - I would prefer stuff like fastmod or semgrep live as plugins. |
Beta Was this translation helpful? Give feedback.
-
@the-mikedavis I think that is a perfectly respectable position. Considering I mostly work with large codebases I expect any editor to have solid regex support comparable to VSCode search and the popular vim grep/ripgrep UIs. That being said, I might be overestimating the impact of such as feature for the average user. I am more than happy to reconsider this as a plugin. As far as I can tell Helix is capable of having competitive performance to ripgrep & fzf with some planned improvements. Part of me just thinks it would be cool to have these features in an extremely performant package with UI. |
Beta Was this translation helpful? Give feedback.
-
i would prefer to have a command to input :rg for the ripgrep commands... so that i dont need to go to another terminal to input that.... and for sure, if there's a realtime search result list on the right side would be added bonus when inputing the rg command... and when putting the -r (replace argv) ... it shows a preview of modified content in different color would be 200% extra bonus... |
Beta Was this translation helpful? Give feedback.
-
This feature is very useful. I will often use the ability to replace regular expressions in my text editing process.
As a text editor, helix should not assume that regex substitution is only used for code editing. Users can use regular expressions to process any type of text, not just code. This is a more general ability than refactoring functions. The syntax of helix supports multiple cursors and recording macros. These functions are useful. But this is not enough to achieve "regex substitution" capability. (I'm happy to provide some examples if needed). |
Beta Was this translation helpful? Give feedback.
-
I wanted to voice my support for this feature as well. I feel there's less of a use-case within code, but it's absolutely essential when editing any other non-code file. With those files (markdown, etc.), it's easily my most used command. Something as simple as the preparation of creating hyperlinks out of a list of text (as I'm fixing up a lot of files like this at the moment): * Reading 1: This is a title to a link
* Reading 2: This is another title With vim, the command is as easy as * Reading 1: [This is a title to a link](
* Reading 2: [This is another title]( There have been a lot of more complex examples I've come across over the past few weeks of testing out helix, but a proper substitution command (alongside the existing open issue of soft wrap, again usually for non-code files) are the biggest barriers to helix being incredible for both code and non-code text alike. |
Beta Was this translation helpful? Give feedback.
-
Very important workflow, being able to cycle through matches and confirming which to change. In vim that's done via |
Beta Was this translation helpful? Give feedback.
-
@adrian5 You can press |
Beta Was this translation helpful? Give feedback.
-
Ah, neat. I didn't know that. |
Beta Was this translation helpful? Give feedback.
-
I have to agree with @the-mikedavis here, I don't think this belongs in core. The whole editing paradigm is centered around interactive text replacement, not batch operations. With the exception of substitutions across multiple files (which is certainly of debatable value), it's likely to do what you want with multiple cursors. There are many excellent tools out there for non-interactive text editing. For whole workspace changes, I'd just use |
Beta Was this translation helpful? Give feedback.
-
With regex search/replace, you have the ability to use match groups and references to customize how your text will be replaced, so, e.g. An idea: Running Doing this in a plugin... I dunno. Maybe as an officially-blessed 1st party plugin? Part of what's so appealing about Helix is how powerful it is out of the box without the need for endless configuration of poorly-interacting plugins a la modern vim. Full-featured interactive search/replace is universally-applicable across editing tasks, and 100% batch-mode tools like sed are not really a replacement. |
Beta Was this translation helpful? Give feedback.
-
Not that my opinion is especially important, but as a long-time Vim user I agree 100%, and I consider the ability to use capture groups an essential feature, for reasons already stated by other folks here.
This is how Kakoune does it (which maybe you know, since you mentioned Ctrl-R). IDK if it is important to be consistent with Kakoune, since it's not very widely used at this time, but it wouldn't be a bad thing to use the same keystrokes, if there's no compelling reason to do otherwise. |
Beta Was this translation helpful? Give feedback.
-
I use regex captures almost daily in neovim. A good example is deciding that I want to invert a match in rust for some reason: |
Beta Was this translation helpful? Give feedback.
-
I added my own command: I don't think this is master-worthy since it doesn't do things like live matching, but it's nice for any time you really need capture replacement (just uses regex crate replace and replace_all, so the capture groups are $0, $1, $n) |
Beta Was this translation helpful? Give feedback.
-
Can case-agnostic case-preserving replace be done with the current model? |
Beta Was this translation helpful? Give feedback.
-
An outside opinion: Helix makes it convenient enough to pipe the selection through external tools, and |
Beta Was this translation helpful? Give feedback.
-
That's a really neat trick! @lukepighetti I think it can be a good topic for another cool Helix video. Usage of (?-i) prefix to switch case could also benefit from some light and it's within the same topic. |
Beta Was this translation helpful? Give feedback.
-
How about allowing the use of capture groups during select_regex? This would allow you to match on a larger string, while setting the actual selection to one or more capture groups. For example, you could match email addresses while using a capture group to select only the usernames or domain names. After that, you can edit with multi-cursors as usual. |
Beta Was this translation helpful? Give feedback.
-
Support regex substitution, comparable to vim
:s
or VSCode search & replace.I propose supporting regex replacements for selection
s
, files/
, and the workspace scopes<space> + /
.This could be accomplished a few ways, but I would specifically propose using
/
as a reserved character for regex select operations. This would allow supporting replacement through the common/select/replace/g
syntax wherever regex is used.As far as I can tell workspace scope find replace is considerably more complex to implement than the others. The current
grep -> fuzzy filter files
user interface would likely be unergonomic compared to alive_grep
UI for the regex replacement usecase.Q: Why not use idiomatic helix multi cursor functionality
s:
to replace matchesA: I believe the most productive feature of regex substitution are capture groups which are not replicated with multi-cursor.
Beta Was this translation helpful? Give feedback.
All reactions