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.json
it 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):g
command 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 bettervim
user that way...-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 :)