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


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, 2016 at 15:01

1 Answer 1


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:


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 and acknowledge you have read our privacy policy.

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