4

I just don't undstand the VIM help for pattern matching and substitution. I've tried.

I have many lines of code, like so:

G1 X139.164 Y115.348 E8.40357 ; perimeter
G1 X138.903 Y115.845 E8.57778 ; perimeter
G1 X136.919 Y119.355 E9.82896 ; perimeter
G1 X135.204 Y125.148     F250    
G1 X133.565 Y124.281 E11.75686     F250    

I want to remove uppercase E and everything following it on each line - or truncate each line, beginning with the E.

Things I've tried:

:%s/E\>//g
:1,$/E\>\.//
:%s/E\>\zs.*//

Please help.

Davo
  • 176
  • 3
  • 12

3 Answers3

7

You can use this command:

:1,%s/E.*$//g
Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
5

@Christopher Collins' solution is great. Here's one more way you could do it:

:%norm fED

This tell vim to press fED on each line as if you had typed it in normal mode. fE will move the cursor forward to the first E, and D deletes everything until the end of the line.

DJMcMayhem
  • 17,581
  • 5
  • 53
  • 85
4

Your last attempt is almost correct. I would use this:

:%s/E.*//

The OCD part of me would also want to remove any spaces before the E. That could be done with:

:%s/\s*E.*//

The \> was causing your attempts to fail because by default numbers are considered part of the word. See :help \> and :help iskeyword for more info.

The \zs isn't necessary in this case since you are trying to replace the entire search pattern. If you were to use it, you would want it in front of the E since you want to remove the E as well. The \zs would be useful if, for example, you only wanted to remove the E and everything after on lines starting with G2. Then you could do something like:

:%s/^G2.*\zs\s*E.*//

Pak
  • 1,114
  • 6
  • 12