I've got, in this case, a Perl module which has some JSON
snippets inside of it. I'd like to be able to select the embedded JSON
and format it via jq
. So far I've got:
:vnoremap jq <esc>:'<,'>:w !jq<CR>
That allows me to select some text, type jq
and then the formatted text is displayed to me. However, it's not replacing the selected text. Nothing actually changes in my buffer. What am I missing here? I've seen lots of answers for how to format an entire file, but I can't find a workable answer for this particular use case.
:h 'formatprg'
What am I missing here?
Removew
. (In fact, just:!jq<CR>
is enough, the rest is a garbage).jq
's help menu inserted into my file.formatprg
. That's very handy. If I try:set formatprg=jq
and then select the text and entergq
, the JSON is replaced with the help text fromjq
. I guess it's an issue with howjq
is being invoked.vnoremap jq :!jq<cr>
works for me.