Claus Witt

I hand edit json many times a week. For that reason the vim command for doing a quick pretty printing of json in current buffer usually is muscle memory for me; however I mistyped it twice today, and decided to make a command and a keybinding for it instead. (Even though I will probably forget it in a couple of days, and revert to typing the command by hand).

Nevertheless; here it is if you need it:

function! JsonPrettyPrint()
  %!python -m json.tool
endfunction


noremap <Leader><Leader>jp :call JsonPrettyPrint()<cr>
command! -nargs=0 JsonPretty :call JsonPrettyPrint()

First we define the function, and it is really just a function name wrapping the command that I mistyped today.

Then we bind a key-binding to it; in my case ,,jp

And finally we also make a command that can be called by typing :JsonPretty in normal mode.


Recent posts