micro icon indicating copy to clipboard operation
micro copied to clipboard

replace doesn't allow regex

Open dprr opened this issue 4 years ago • 3 comments

Description of the problem or steps to reproduce

Say I want to replace 4 spaces with a tab:

  1. Type CtrlE to get the command window
  2. Type replace ' ' '\t'

That would replace 4 spaces with the \t literal rather than a tab character

Specifications

Version: 2.0.4 Commit hash: c5b0c2d OS: Linux 5.6.13-arch1-1 Terminal: Fish

dprr avatar Jun 03 '20 17:06 dprr

I’ll look into fixing this. In the meantime I recommend using the > retab command (along with the appropriate tabstospaces value you want) to achieve what you want.

zyedidia avatar Jun 03 '20 17:06 zyedidia

thanks

dprr avatar Jun 04 '20 03:06 dprr

Note this issue isn't really about regex, but ANSI C Escape Sequences, of which \t, \n, and \\ are really common. These can be expanded e.g. in a Bash shell with e.g. printf $'here are 2 tabs "\t\t" and a newline\n'.

It looks like it might be enough to pass the replacement string through fmt.Sprintf to interpret the codes, but maybe this would complicate the selection boundaries after replacement.

AndrewDDavis avatar Dec 07 '23 17:12 AndrewDDavis