2

Background:

I can pipe a paragraph through an external command using !ip and the cursor goes to the end of the following prompt:

:.,.+5!

If I want to use the built-in sort or center functions I could specify the line numbers manually, but I have relative numbers so I would need to count or use visual mode. So currently I use, for example, !ip<backspace>sort or !2}<backspace>center. This gives me the flexibility to use any kind of range for the command, and I can run it from anywhere inside the range.

Question:

Is there a way I could do something similar to !<range> but ending up without the ! at the end of the prompt, that I then need to delete? Something like <foo>ipsort to end up with :.,.+6sort.

5
  • 1
    it is explained in the help: :h N: Apr 13, 2017 at 14:12
  • That doesn't work in the middle of a paragraph though, whereas !ip for example would.
    – ACP
    Apr 13, 2017 at 14:15
  • 2
    How about using vip:sort?
    – Tumbler41
    Apr 13, 2017 at 14:44
  • That's the closest I've found, I was wondering if there was a way to do this but without the visual select.
    – ACP
    Apr 13, 2017 at 15:00
  • I'm confused, but could a mapping like nnoremap ps :.,sort<left><left><left><left> helps you? It gives you a prompt prepared to sort from here (. is already set) and you can set the end point for the range.
    – nobe4
    Apr 14, 2017 at 18:49

2 Answers 2

2

the vim range command supports relative ranges. So if you are anywhere in your paragraph and you do not want to use visual mode, you can type i.e.:

:-1,+2!

Which would use the line above the current line and the following two lines.

If you would like to know more about ranges :h range.

0

As far as I know this isn't built-in. However, since it !{motion} results in the notation :<range>! you can just remove the ! in command-line mode and enter your ex command instead. For the :sort command, it could be done like this !{motion}<BS>sort (e.g. !ip<BS>sort)

1
  • I think OP does that but is looking for a cleaner solution
    – Biggybi
    Apr 4 at 5:18

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.