1

As simple example, take this:

:'<,'>s/\vs([A|B])\.size\(\)/\={"A":"a","B":"b"}[submatch(1)]/g

This substitution will replace sA.size() with a and sB.size() with b.

I would like to use lua syntax after \= command. So it will be something like

:'<,'>s/\vs([A|B])\.size\(\)/\={A="a",B="b"}["%1"]/g

Is it possible to do that in nvim? I could not find anything about this.

0

1 Answer 1

1

What you could do is:

:'<,'>s/\vs([A|B])\.size\(\)/\=luaeval('({A="a",B="b"})["'..submatch(1)..'"]')/g

The expression first build the ({A="a", B="b"})["A"] sub-expression using submatch using VimScript concatenation .. operator.

It is evaluated as a Lua expression in a second step by luaeval.

2
  • That's amazing that this is working! I wonder what you did by '..submatch(1)..'. Why there is a ' inside a " and concatenation .. inside a "'? Where I can read more about this? Jun 25 at 21:17
  • 1
    The expression first build the ({A="a",B="b"})["A"] sub-expression using submatch using VimScript concaténation .. operator. It is evaluated as a Lua expression in a second step. Jun 26 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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