3

I want to format a block of text and I am using a range to select the leading comment of a function. It's all lines starting with // ....

I'm using the range

:?^[^\/][^\/]?+1,/^[^\/][^\/]/-1

to select backwards up to the first line not starting with //, then plus one to get the the start of the comment, and similar thing for the forward search.

If I prefix this with a sed command like s,^,#, this works. But if I use gq or gw as command it fails telling me Not an editor command: ...

How can I apply the text format command to a range?

  • 7
    gq and gw are normal commands: you can't enter them in command mode like :gq... that's why you get Not an editor command. You can use normal gq to use them in a script. – statox Mar 31 '16 at 15:01
2

Per @statox comment...

Using normal commands applied to ranges is the same as when they are used in scripts, requiring the normal function to be called.

:?^[^\/][^\/]?+1,/^[^\/][^\/]/-1norm gq

A very common example of this is applying a macro to each line in a visually selected area. Lets say you want to uppercase the last word on each line:

qq$viwUq

If you visually select an area and enter command mode you can apply the macro using normal

:'<,'>normal @q

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.