1

I was wondering if it is possible to combine the gq operation with other commands, as one might do with the | operator. For example, it would be nice to be able to write a command like :'<,'>left4 |gq. However, vim says that gq in this context is not an editor command, because it is interpreting it as :gq. Is there any workaround?

6

You can run normal mode commands from the command-line with the :normal command.

In this instance, we want to first reselect the visual selection, and then run the gq command:

:'<,'>left4 | norm! gvgq

See :help :normal and :help gv for more details.

3
  • Is there a way to do this with a global search & replace so you reindent as you go?
    – Steve
    May 2 '18 at 7:08
  • @Steve You mean something like this? :%s/foo/bar/g | norm! gggqG
    – Rich
    May 2 '18 at 8:51
  • Doh of course I forgot the go to beginning bit. Thanks
    – Steve
    May 3 '18 at 2:28

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.