Save a read-only file in VIM using sudo

Have you opened a read-only file and modified it but couldn't save? Not anymore, I found a quick tip which allows VIM users to save the file as 'sudo' even if you didn't use 'sudo' at the time of opening.
Create a shorthand mapping in VIM as follows:

cmap w!! %!sudo tee > /dev/null %

You can save this to your ~/.vimrc file to persist it.

Now every time you want to override the read-only status and save changes as sudo, just hit 'w!!' and you'll be good.

Love the power of VIM!

This entry was posted in Tips and tagged , . Bookmark the permalink.
  • Thomas John

    Hello,

    I am Thomas John representing Content Grid.
    We are a team of content writers from all over the world who specialize
    in developing content for a variety of websites including ubuntumanual.org and zyxware.com

    We have an upcoming website zyxpm.com
    and we were seeking talented writes with a flair for programming to
    join our community of writers. We happened to come across your blog  on
    the web and we were wondering whether you would be interested in writing
    programming related articles for us.

    We
    can provide sufficient compensation for your writings and we are
    looking forward  to having you as one of our writers in our community.
    If you are interested in this opportunity then please  contact us for
    the work description and rates.

    Contact id: thomas.john@zyxware.com   

    Cheers,
    ————–
    Thomas John
    Content Grid.