This is very similar to how-to-run-bash-command-over-current-file-and-replace-buffer-with-result

But I need to know how I can access current buffer when the file does not exist? i.e.

  1. I open vim
  2. goto insert mode e,g, press : i
  3. paste a json, possibly incomplete
  4. Run the command !% jq

For now I get output as error from jq.

  • forgot to add link stedolan.github.io/jq – comdotlinux Jan 2 '18 at 12:41
  • How is this question different from post you linked? The answer seems to be the same, use the filter command with a range. i.e. :%! jq – Peter Rincker Jan 2 '18 at 15:47
  • @PeterRincker The range operator doesn't work with an unnamed or unsaved buffer. – Tim Jan 2 '18 at 16:26
  • 2
    You can filter a whole buffer with %!. Even an unnamed, unsaved buffer. I have tested and verified that :%!jq '.' works to prettify JSON. – Peter Rincker Jan 2 '18 at 16:31
  • correct. filtering works even for unnamed buffers. Please include more information why it wouldn't work for you (e.g. error message). – Christian Brabandt Jan 2 '18 at 16:40

Browse other questions tagged or ask your own question.