Reputation: 57
I want to trim the last five characters of a match in Vim. The search pattern is not a direct word, instead it is something like foo.*bar
Here I want to trim the last five characters of the above match.
I tried :g/foo.*bar/norm $5X
but this trims five characters at the end of the lines matching this pattern
Upvotes: 0
Views: 188
Reputation: 196496
:help :global
is not the right tool for the job.
With a substitution:
:%s/foo.*bar/\=submatch(0)[:-6]/g
See :help sublist
and :help submatch()
.
Upvotes: 3