To support my work, I’ve enabled ads on my blog. I hope you don’t mind them, as they help me continue creating valuable content. Your understanding and support mean the world to me! Thank you!
These are the vim one-liners I reach for most when editing files. Each one replaces a task that would otherwise take several manual steps.
- Count the Number of Words in a File:
A simple vim one-liner that counts the words in the file. Handy when you need a quick count without leaving the editor.
:%s/\w\+/\=submatch(0 ) +1/g | echo line( '$' ) - Format JSON with Python:
This one uses Python’s json library from inside vim to format a JSON document. Useful when you need to format a large JSON file locally.
:%!python -m json.tool - Remove all the blank lines
Removes all blank lines from the file you are working on.
:g/^\s*$/d - Opening Multiple Files at once in split mode
:argedit file1.txt file2.txt | all - Calculating the sum of all numbers present in the file
:put =eval(join(getline(1, '$' ) , '+' ) ) - Extracting IP Addresses
:g/\(\d\{1,3}\.\ ) \{3}\d\{1,3\}/y A If you have a vim tip or one-liner of your own, share it in the comments below. I would love to check it out.
I write occasionally; feel free to follow me on Twitter. To get new posts by email, subscribe to the newsletter.