[linux-elitists] lawyers, vim, software patents

Aaron Lehmann aaronl@vitelus.com
Sat May 12 15:45:26 PDT 2001


On Sat, May 12, 2001 at 01:51:45AM -0700, Don Marti wrote:
> I'd like to look at people's .vimrc files for an LJ piece; if you have
> anything particularly cool in yours, please post it and I'll give you
> appropriate credit if I use it.

Looking at .emacs files would be so much more fun...

The only original thing I have of any value for vim is a macro to
comment out the current line of C code:


	autocmd BufRead *.c,*.h map gc :s/[^ \t]//gc
qi/* A */0j

...And a matching one to uncomment the comment under cursor:

	autocmd BufRead *.c,*.h map  :set nows
$?\/\* *
:s,/\* *,,
0/ \=\*\/
:s, \=\*/,,
:set ws
j

I'm not very proud of either.

In the standard-vim-practice department, we have word-wrapping for mail
messages...

augroup mail
   au!
   " Set up my defaults when editing mail
   autocmd BufNewFile,BufRead motd,[dD]raft,bug*,cvs*,.letter,.followup,.article,.article.[0-9]\+,mutt*[0-9]      set formatoptions=tqv2c noai textwidth=70 nobackup noautoindent noml
augroup END 

Ever wanted vim to automatically and transparently edit compressed
files? Credit for this goes to Debian, AFAIK.

augroup gzip
  au!
  autocmd BufReadPre,FileReadPre	*.gz set bin
  autocmd BufReadPre,FileReadPre	*.gz let ch_save = &ch|set ch=2
  autocmd BufReadPost,FileReadPost	*.gz '[,']!gunzip
  autocmd BufReadPost,FileReadPost	*.gz set nobin
  autocmd BufReadPost,FileReadPost	*.gz let &ch = ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost	*.gz execute ":doautocmd BufReadPost " . expand("%:r")
  autocmd BufWritePost,FileWritePost	*.gz !mv <afile> <afile>:r
  autocmd BufWritePost,FileWritePost	*.gz !gzip <afile>:r
  autocmd FileAppendPre			*.gz !gunzip <afile>
  autocmd FileAppendPre			*.gz !mv <afile>:r <afile>
  autocmd FileAppendPost		*.gz !mv <afile> <afile>:r
  autocmd FileAppendPost		*.gz !gzip <afile>:r
augroup END

augroup bzip2
  au!
  autocmd BufReadPre,FileReadPre        *.bz2 set bin
  autocmd BufReadPre,FileReadPre        *.bz2 let ch_save = &ch|set ch=2
  autocmd BufReadPost,FileReadPost      *.bz2 |'[,']!bunzip2
  autocmd BufReadPost,FileReadPost      *.bz2 let &ch = ch_save|unlet ch_save
  autocmd BufReadPost,FileReadPost      *.bz2 execute ":doautocmd BufReadPost " . expand("%:r")
  autocmd BufWritePost,FileWritePost    *.bz2 !mv <afile> <afile>:r
  autocmd BufWritePost,FileWritePost    *.bz2 !bzip2 <afile>:r
  autocmd FileAppendPre                 *.bz2 !bunzip2 <afile>
  autocmd FileAppendPre                 *.bz2 !mv <afile>:r <afile>
  autocmd FileAppendPost                *.bz2 !mv <afile> <afile>:r
  autocmd FileAppendPost                *.bz2 !bzip2 -9 --repetitive-best <afile>:r
augroup END



More information about the linux-elitists mailing list