Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Wednesday, 20 June 2012

Vim formatting goodness

So I wanted to paste this licence into my piece of code http://www.opensource.org/licenses/bsd-license.php

But I wanted it be wrapped to no more than  79 characters a line and before each sentence I wanted to insert a "# "

This is how

:set paste (paste text from web browser)
highlight area with shift V

! fmt -77 (keep 2 characters for "# ")
s!^!# !

Love it!

Wednesday, 10 August 2011

Writing files as root in vim

I do this at least once a day; open a file in vim, make changes, then get reminded that I didn't do it using sudo.

simple one-liner fixes this.

:w !sudo tee %

Thanks to http://www.cyberciti.biz/faq/vim-vi-text-editor-save-file-without-root-permission/ for that one.