Skip to main content
Post Closed as "Duplicate" by Martin Tournoij
deleted 1 character in body
Source Link
k0pernikus
  • 3k
  • 5
  • 21
  • 35

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do

jq . ugly.json > formmatedformated.json 

Now, I don't want to leave vim, but run it directly within my current open file.

How can I do it?

I tried:

:!jq . % 

! runs a bash command % means the current file

Yet this only displays the result, yet does not update the content of the file.


While writing this question I stumbled upon a solution yet don't know why it works. It would be great if someone could point out why `:%!jq .` works.

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do

jq . ugly.json > formmated.json 

Now, I don't want to leave vim, but run it directly within my current open file.

How can I do it?

I tried:

:!jq . % 

! runs a bash command % means the current file

Yet this only displays the result, yet does not update the content of the file.


While writing this question I stumbled upon a solution yet don't know why it works. It would be great if someone could point out why `:%!jq .` works.

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do

jq . ugly.json > formated.json 

Now, I don't want to leave vim, but run it directly within my current open file.

How can I do it?

I tried:

:!jq . % 

! runs a bash command % means the current file

Yet this only displays the result, yet does not update the content of the file.


While writing this question I stumbled upon a solution yet don't know why it works. It would be great if someone could point out why `:%!jq .` works.
Source Link
k0pernikus
  • 3k
  • 5
  • 21
  • 35

How to run bash command over current file and replace buffer with result?

I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do

jq . ugly.json > formmated.json 

Now, I don't want to leave vim, but run it directly within my current open file.

How can I do it?

I tried:

:!jq . % 

! runs a bash command % means the current file

Yet this only displays the result, yet does not update the content of the file.


While writing this question I stumbled upon a solution yet don't know why it works. It would be great if someone could point out why `:%!jq .` works.