0

I want to be able to use some normal commands I tend to use in the day to day as an input for another function, for example 4X, I would like 4X to be expanded to XXXX and then use it in a function as :substitude(s, 'here', <expand result of 4X>, 'g')

It's there an easy way to set this up?

2
  • 1
    To me this is a duplicate of How do I use a variable or return value in option, command, or mapping?
    – statox
    Jul 20, 2020 at 13:23
  • 1
    2 points: the command is :substitute, and it has an eponymous function substitute(); the command can be run with a colon, but does not use left/right parens like a function—it uses a delimiter character to separate pattern/replacement/flags. The function uses parens, and must be :called or appear in an expression position (like after :echo or on the right-hand side of a :let).
    – D. Ben Knoble
    Jul 20, 2020 at 13:26

1 Answer 1

4

In this specific case, you have repeat(4, 'X').

Otherwise, normal and command mode commands don't return anything. They may echo messages (which we can get with execute()), or they can do any kind of action (compile, move cursor, change focus, open/close buffers/windows, change the buffer...). We can't provide a generic answer to your question as there is none.

What are your specific use cases? repeat(). What else?

1
  • 2
    On this case repeat works just fine, I believe that there most be plenty of vim functions I just need to get to know for each use case but this one tackles the issue perfectly. Thanks for the quick answer!
    – Hassek
    Jul 20, 2020 at 13:49

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.