June 7, 2015
Last Friday, Cyril pinged for an after-office beer party. It’s all legitimate for a Friday evening :-)
At my workplace I in-turn bugged Kaviraj, a networking fellow who enjoys the usual geek talks.
We finished work and reached Flying Dodo some time after 19h00. Cyril and the others had taken the table outside. We could that way enjoy the cozy weather, not too warm neither cold, listen to the live band and have a chilled beer. To make it more fun I asked for pizza.
A while later Mike joined us. Kaviraj, Mike and I got into some fun chatting about CLI tools. Mike was talking about “vi” and we shared the handy tricks when editing config files.
Commenting multiple lines in VimTo toggle between line numbering and without line numbers, do
:set nu!. The line numbers are useful when editing config files, say when you need to comment a block of directives (e.g from line 15 to 25). You would do
:15,25s/^/#/gto comment and commenting out would be
In-line replacement of a wordAt times you find a long word in a line which you need to replace. While your cursor is at the beginning of the word, you press
cwand enter the new word. It’s replaced. Is it difficult to remember
cw? Just remember “change word” :-)
Saving with “root” privilegeEver edited a file and while saving you realise you actually require super-privilege? It happens when you are tinkering as a regular user and the file is owned by root. If you’re a sudoer then the following could save you time:
:w !sudo tee %
! symbol allows you to execute shell commands and the
% signifies the current file. We’re thus saying update by sending the content to the current file with sudo privilege.
Find and replaceTo trigger a find we could simply do
nto hop to the next occurrence of the word. We could search the whole file for a particular word and replace all occurrences:
We could also limit the find & replace within a block of lines.
For more fine-tuning of the search, regular expressions would come handy.
Kaviraj & I left Flying Dodo at 21h00. That was a short moment having a geek chit-chat with like-minded folks.