Wednesday, September 22, 2021

Re: Specify a range for a python command alias

Hi,

Haslett, Garvin schrieb am 22.09.2021 um 13:04:
> Following the web page listed below I've created the following command alias in my .vimrc to conveniently prettify .json files:
> command! Pj %!python -m json.tool
>
> It works great but, ideally, I'd like to specify ranges. I tried the following:
> command! -range=% Pj !python -m json.tool
> But the command just hangs until such times as I Ctrl-C to abort.
>
> I'm surprised by this since entering `3,4!python -m json.tool` at the command buffer works as expected.
>
> What subtlety am I missing here?

you need to tell Vim where you want to insert the range into
the replacement text for the user-defined command. You do this
by including the escape sequence <range> in the replacement
text.

In your case

:command! -range=% Pj <range>!python -m json.tool

should do the trick.

Regards,
Jürgen

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/4e193854-be1d-20c5-9456-b62adbf30eb3%40googlemail.com.

No comments:

Post a Comment