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!
In this post, I will be sharing my favorite vim
one-liners that have significantly enhanced my vim
workflow, making it more productive and efficient. As an avid vim
user, I have extensively utilized these one-liners to edit files, and they never cease to surprise me with their ability to accomplish tasks swiftly, saving precious time. This is precisely what drew me to Vim - the unparalleled efficiency it offers when it comes to editing text.
- Count the Number of Words in a File:
A simple vim one liner which allows you to count the words in the file as this can be very handy.
:%s/\w\+/\=submatch(0)+1/g | echo line('$')
- Format JSON with Python:
Now this command is very simple but it allows you use python json library within vim to format your json document and its very useful when you need to format large json documents locally.
:%!python -m json.tool
- Remove all the blank lines
This allows you to remove all the 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
Lastly I hope you enjoyed reading this and got a chance to learn something new from this post and if you have any vim tips or one liners feel free to comment below and I would love to check it out.
I write occasionally feel free to follow me on twitter, also I run a newsletter and if you like reading technology news you can subscribe here