For sure it must have happened so many times with you too that after making several edits to a file through Vi, you realise it’s a read-only file and you would need root privilege to save the modifications. Well… Next time you face it, don’t pull your hair, just try this:

:w !sudo tee %