VIM CHEATSHEET

The ~/.vimrc file sets options when vim is started.

" .vimrc
set encoding=utf-8
set fileencoding=utf-8
set background=dark    " Set dark mode for Solarized
set ruler              " Show status line    
set showcmd            " Show (partial) command in status line.
set showmatch          " Show matching brackets.
set ignorecase         " Do case insensitive matching
syntax enable          " Syntax Highlighting
colorscheme default    " Set colorscheme 
" Remember last position
autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
     \   exe "normal! g`\"" |
     \ endif

Vim commands.

Append File           :w>>file
Delete Character      x
Colorscheme List      :colorscheme ^d
Syntax Highlight      :syntax on
Copy Line             yy
Delete Line           dd
Delete Word           dW
Display Line Numbers  :set nu :set nonu
Edit File             vi filename
Insert mode           i ESC
Insert New Line Above O
Insert New Line Below o
Move Beginning of Line ^
Move End of Line      $
Move First Line       :0
Move Last Line        G
Move Screen Forward   ^f
Move Screen Backward  ^b
Move Word Back        b
Move Word Forward     w
Overwrite Text        R
Paste Above           P
Paste Below           p
Replace Character     r
Quit                  :q!
Search                /word
Search Next           n
Search Replace        :line1,line2s/old/new/gc
Search Replace        :.,$s/old/new/gc #cur line to end
Undo Last Change      u
Write                 :w
Write Quit            ZZ
Write quit            :wq

Create a PDF.

vim states.txt -c "hardcopy > states.ps | q" && ps2pdf states.ps

VIM Backup file before changes

" VI Automatic Backup
" Add this to .vimrc to backup files before changes

"Turn on backup option
set backup

"Where to store backups
set backupdir=~/.vimbackup/

"Make backup before overwriting the current buffer
set writebackup

"Overwrite the original backup file
set backupcopy=yes

"Meaningful backup name, ex: filename@2015-04-05.14:59
au BufWritePre * let &bex = '@' . strftime("%F.%H:%M:%S")