1

For writing a text book I would like text expansion; on typing this:

|25,50,65|

it should expand this to:

$25\ux,50\uy,65\uz$

I tried to use simple text replacement with :s%/TEXT/NEWTEXT/gc, but problem is my requirement with three arguments vim should wrap some text around three arguments.

The same problem exists with iabbrev, plus iabbrev requires typing TEXT and then a space.

How can I achieve this in Vim?

0
3

You can change any set of numbers (e.g. 24,10,4 to $24\ux,10uy,4uz$) with something like this:

:%s/\v(\d+)(,\d+)(,\d+)/$\1\\ux\2\\uy\3\\uz$/g
3
  • I tried in ESC mode, but it says invalid argument. Pls help Sep 3 '16 at 9:40
  • @RamaKrishnaMajety Because the plus has to be escaped. Put a backslash before each one. (but I don't think this is the invalid argument problem)
    – Al.G.
    Sep 3 '16 at 11:26
  • 1
    I forgot the : - it's a substitution. The plus doesn't need to be escaped, since I use the very magic \v switch.
    – VanLaser
    Sep 3 '16 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.