doc tricks

" vi tutorial, tips, tricks and useful commands
" from http://www.cs.ualberta.ca/~luca/tricks.vim.html
" updated and hacked a little by Greg Lawler

" Where grep came from (RE being Regular Expression):
:g/RE/p

" Delete lines 10 to 20 inclusive:
:10,20d
" or with marks a and b:
:'a,'bd

" Delete lines that contain patt:
:g/patt/d

" Delete all empty lines:
:g/^$/d

" Delete lines in range that contain patt:
:20,30/patt/d
" or with marks a and b:
:'a,'b/patt/d

" Subsitute all lines for first occurance of patt:
:%s/patt/new/
:1,$s/patt/new/

" Subsitute all lines for patt globally (more than once on the line):
:%s/patt/new/g
:1,$s/patt/new/g

" Subsitute range:
:20,30s/patt/new/g
" with marks a and b:
:'a,'bs/patt/new/g

" Swap two patterns on a line:
:s/\(patt1\)\(patt2\)/\2\1/

" Capitalize the first lowercase character on a line:
:s/\([a-z]\)/\u\1/
" more concisely:
:s/[a-z]/\u&/

" Capitalize all lowercase characters on a line:
:s/\([a-z]\)/\u\1/g
" more concisely:
:s/[a-z]/\u&/g

" Capitalize all characters on a line:
:s/\(.*\)/\U\1\E/

" Capitalize the first character of all words on a line:
:s/\<[a-z]/\u&/g

" Uncapitalize the first character of all words on a line:
:s/\<[A-Z]/\l&/g

" Change case of character under cursor:
~

" Change case of all characters on line:
g~~

" Change case of remaining word from cursor:
g~w

" Increment the number under the cursor:
<Ctrl-A>

" Decrement the number under the cursor:
<Ctrl-X>

" redraw:
<Ctrl-L>

" Turn on line numbering:
:set nu
" Turn it off:
:set nonu

" Number lines (filter the file through a unix command and replace with output):
:%!cat -n

" Sort lines:
:%!sort

" Sort and uniq:
:%!sort -u

" Read output of command into buffer:
:r !ls -l

" Refresh file from version on disk:
:e!

" Open a new window:
<Ctrl-W>n

" Open a new window with the same file (split):
<Ctrl-W>s

" Split window vertically:
<Ctrl-W>v

" Close current window:
<Ctrl-W>c
:q

" Make current window the only window:
<Ctrl-W>o

" Cycle to next window:
<Ctrl-W>w

" Move to window below current window:
<Ctrl-W>j

" Move to window above current window:
<Ctrl-W>k

" Move to window left of current window:
<Ctrl-W>h

" Move to window right of current window:
<Ctrl-W>l

" Set textwidth for automatic line-wrapping as you type:
:set textwidth=80

" Turn on syntax highlighting
:syn on
" Turn it off:
:syn off

" Force the filetype for syntax highlighting:
:set filetype=python
:set filetype=c
:set filetype=php

" Use lighter coloring scheme for a dark background:
:set background=dark

" Htmlize a file using the current syntax highlighting:
:so $VIMRUNTIME/syntax/2html.vim

" Or, htmlize from a command prompt:
" in 2html.sh put:

#!/bin/sh
vim -n -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null

" Now just run:  shell> 2html.sh foo.py