-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
> replace powerful or confusing? #3279
Comments
Some notes, not in any particular order:
I just tried
and it worked fine. Maybe this is specific to Windows. However, I also tried
and that did not work. I investigated a bit and my best guess is that this is because the ReplaceRegex function (in
This is incorrect, for reasons I explain lower. There are 8 combinations:
However, I'm not quite sure how important the number of combinations is to explaining how the commands work. Shell splitting and the regex/literal flag are orthogonal features that will naturally multiply the amount of possible combos, but I don't think it's helpful to think about them in that way. Instead, it would be better to explain them as separate features, and then maybe give some examples of how they could interact.
I was staring at this for a while, confused by the [[]].
Same goes for
After a quick glance at the code, it looks like it does not. Shell splitting is performed for all commands, before micro even knows what the command is. So you actually can't prevent shell splitting, barring some new feature being added.
As reported in #2666, I see. Fixing it properly would probably require either forking kballard/go-shellquote, or finding and implementing some workaround on micro's side. Either way, I think that a hard crash is not acceptable here. |
Hi Many thanks for your contribution, I have updated the top post with credits. I can't get shell parsing to work on Windows, any examples of using or escaping welcome. Kind Regards Gavin Holt PS. I have removed the [[]] this is my go-to alternate string delimiter, if I don't want to use quotes (used in DOS batch files and in Lua) |
Hi
Could someone more knowledgeable than me check this help file I have made for the replace/replaceall command.
Kind Regards Gavin Holt
OS: Windows 10
Version: 2.0.13
Commit hash: 68d88b5
Compiled on April 20, 2024
Replacing text in micro editor
The flags are optional. Possible flags are:
If you make a selection, search and replace will only happen in the selected region.
Instructions to the replace command may end up being be parsed twice - once by the shell argument parser, and then by the regex parser. This causes problems with special characters.
This gives eight combinations:
Replace will search for
\t
ASCII escape sequence:e.g. Expand all tabs to four spaces (the expand utility might be better)
or
I could not get replace to insert
\t
.It appears that replace works on single lines only, so you can't find or insert
\n
nor\r
.Simple replacements
Strings without spaces don't need to be quoted, but replace behaves as if there are double quotes (read below)
e.g.
e.g.
Strings with spaces need to be quoted, and the type of quotes changes behavior.
Working without shell parsing (Single quotes)
The Regex parser will look for metacharacters:
Escape metacharacters with
\
except for $ which is different.$foo
$
charactere.g. Replace all $ with £
e.g. Replace all \ with /
e.g. Replace all " with ' needs double quotes for the replacement.
Capture groups are recognised:
foo
e.g.
NB. Any command ending in a \ will kill micro on Windows.
Working with shell parsing (Double quotes)
Some characters must be escaped twice to reach the underlying functions. Shell parsing does not seem to work in Windows (either with $ prefix or wrapped in %%)
The following characters are special to the shell parser:
Escape with
\
or\\
depending upon what you want to pass to the replace functione.g. Replace all $ with £
e.g. Replace all \ with / - requires extra \ to preserve the closing "
Further examples using/escaping shell parsing need to go here
Working with the '-l' flag
The '-l' flag turns off regex parsing to allow literal replacements. However, with double quotes there is still shell parsing so some escaping is required.
Replacing control character
I use external tools instead:
The text was updated successfully, but these errors were encountered: