4 ms·
Hello HN, I'm the author of this post, and I hope you enjoyed reading it. I wanted to share this one-liner for fun: :%s/\w\+/\=submatch(0)+1/g | echo line('$'
by mr_o47 3y ago
Hello HN,
I'm the author of this post, and I hope you enjoyed reading it.
I wanted to share this one-liner for fun:
:%s/\w\+/\=submatch(0)+1/g | echo line('$')
Although I know there are more efficient ways to count words in a file using Vim, I wanted to be a little creative.
Lastly, I want to express my deep sadness over the passing of Bram Moolenaar. He created an extraordinary text editor that had a profound impact.
Rest in Peace Bram Moolenaar
- function_seven 3y agoI also snarked a bit when I saw your word count example, but immediately reversed course when I saw the JSON formatting one-liner. I will use this. I will use the hell out of it. Thanks! RIP Bram.
- TonyStr 3y agoWhat does `%!python -m json.tool` offer that `%!jq` doesn't?
- function_seven 3y agoI don’t know. I’m assuming I should install jq (or see if I already have it?) Here’s the problem I have: I don’t often have to format unformatted JSON, but when I do, it’s almost always an error message I’m trying to parse in order to track down a bug. So I tell myself “I should really figure out how to automate this…I know it’s obviously possible, but I just really wanna fix this bug right now, so I’ll do that later.” And then the next time it happens, I curse myself for not having researched that, and promise to do it before the next time. So I’m just happy that I stumbled across this page. Now I don’t have to remember to research it :)
- cerved 3y agoChances are higher that python is installed than jq, other than that can't think of any