When I need to work with some scrambled javascript/json code, one of my first steps is to introduce proper line breaks, followed by proper brace based indentation. For the later, I found the following command very helpful:
:%g/{/:normal $>i{
With at most a single opening brace on any line, this produces near perfect indentation in no time.
However, when trying to run the same command from the command line with the -c option, it simply does not seem to have any effect. I tried the following invocation:
vim -c ':%g/{/:normal $>i{' -c ':wq' some_scrambled_json_file.json
Why does this not work? And how do I need to change my invocation to make it work?
python -m json.tool bad.json > good.jsonit will save you the trouble to use vim for something it is not intended to do. (I said python because that's what I use but you can do the same with any other scripting language) – statox Jan 19 '18 at 13:23:gcommand behaves so much differently when invoked from the command line. So, I guess my main motivation for asking is, that I hope to become a bettervimuser that way... – cmaster - reinstate monica Jan 19 '18 at 13:31vimversion is 8.0 as well, but I guess we have some differences in our.vimrcfiles that make the difference. If nobody comes up with a bright idea soon, I guess, I'll just delete this question as its problem does not seem to be (easily) reproducible, and thus likely worthless to others. Anyway, thanks for your effort in checking :-) – cmaster - reinstate monica Jan 19 '18 at 14:34-U NONE) if it works well you can check how to debug my vimrc? And yes, wait a bit before deleting your question some people here are amazing vim experts, they might come up with a solution. Happy vimming :) – statox Jan 19 '18 at 14:45