Created
August 27, 2011 04:06
-
-
Save suderman/1174960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim Installation | |
" ---------------- | |
" 1. Install MacVim 7.3 — http://github.com/downloads/b4winckler/macvim/MacVim-snapshot-61.tbz | |
" 2. Install vim-update-bundles — git clone git://github.com/bronson/vim-update-bundles.git | |
" 3. Run ./vim-update-bundles | |
" | |
" Vim Cheatsheet | |
" -------------- | |
" ⎋ normal mode | |
" i insert mode before (I beginning of line) | |
" a insert mode after (A end of line) | |
" | |
" v visual mode | |
" V visual line mode | |
" ⌃v visual block mode | |
" | |
" gv reselect the text from the last visual mode | |
" gV select the text that was last edited/pasted | |
" | |
" u undo | |
" ⇧u redo | |
" ,u toggle undo history (gundo) | |
" | |
" y yank | |
" d delete | |
" p paste (⌃p to cycle history) | |
" [p toggle clipboard (yankring) | |
" ,p toggle paste mode (pasting from GUI clipboard) | |
" | |
" jkhl move the cursor | |
" ⌃jkhl move the cursor (insert mode) | |
" ⌃jkhl move focus between windows (normal mode) | |
" ⌃jkhl resize windows (visual mode) | |
" ,jkhl move windows | |
" ,, full screen current window | |
" | |
" ,- split window horizontally | |
" ,= split window vertically | |
" ,c close window | |
" | |
" ,t new tab | |
" ,cc close tab | |
" ⇧h previous tab | |
" ⇧l next tab | |
" ⇧k list buffers | |
" | |
" u redo | |
" ,u toggle undo history (gundo) | |
" | |
" y yank | |
" d delete | |
" p paste (⌃p to cycle history) | |
" [p toggle clipboard (yankring) | |
" ,p toggle paste mode (pasting from GUI clipboard) | |
" | |
" jkhl move the cursor | |
" ⌃jkhl move the cursor (insert mode) | |
" ⌃jkhl move focus between windows (normal mode) | |
" ⌃jkhl resize windows (visual mode) | |
" ,jkhl move windows | |
" ,, full screen current window | |
" | |
" ,- split window horizontally | |
" ,= split window vertically | |
" ,c close window | |
" | |
" ,t new tab | |
" ,cc close tab | |
" ⇧h previous tab | |
" ⇧l next tab | |
" ⇧k list buffers | |
" | |
" ⇧<page-up> scroll up one page (also ^b) | |
" ⇧<page-down> scroll down one page (also ^f) | |
" | |
" _+ bubble lines up/down (visual mode) | |
" >< indent, outdent (visual mode) | |
" gcc toggle comments | |
" = auto format | |
" | |
" ^_ close last HTML tag | |
" | |
" /.../ search in file (n to cycle results; ,<space> to clear highlights) | |
" ,a search in project (Ack) | |
" ,g search file names (⌃c to cancel) | |
" | |
" ⇧<tab> cycle buffers | |
" ,6 alt file | |
" ,d toggle project drawer (,dd to find current file in tree) | |
" | |
" ,ss toggle spellcheck | |
" ,s? list spelling suggestions | |
" | |
" ⇧zz save and quit | |
" ⇧zq don't save and quit | |
" ⇧zs save (also ,w) | |
" ⇧zx delete buffer, keep window (include s to save) | |
" ⇧zxx delete buffer, close window (include s to save) | |
" | |
" F5 clean up whitespace | |
" | |
" ,m markdown preview | |
" | |
" ;g toggle golden ratio | |
" ;c change colorscheme | |
" ;cc colorscheme browser | |
" ;b toggle background | |
" | |
" :ee open/edit file in current file's directory | |
" ;cd change directory to current file | |
" ;t create a new tab for every open buffer | |
" | |
" ,v open the vimrc (,v again to open gvimrc) | |
" | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set nocompatible | |
set shell=sh | |
" Determine machine (fenring.nonfiction.ca, ginaz.nonfiction.ca, something.local) | |
let hostname = substitute(system('hostname'), '\n', '', '') | |
" Comma is the leader character | |
let mapleader = "," | |
" :! vim-update-bundles | |
silent! call pathogen#helptags() | |
silent! call pathogen#runtime_append_all_bundles() | |
" Plugins installed via vim-update-bundles and loaded via pathogen | |
" :help bundles to list installed | |
" BUNDLE: git://github.com/pangloss/vim-javascript.git | |
" BUNDLE: git://github.com/tomtom/tcomment_vim.git | |
" BUNDLE: git://github.com/ervandew/supertab.git | |
" BUNDLE: git://github.com/msanders/snipmate.vim.git | |
" BUNDLE: git://github.com/Raimondi/delimitMate.git | |
" BUNDLE: git://github.com/tpope/vim-fugitive.git | |
" BUNDLE: git://github.com/tpope/vim-git.git | |
" BUNDLE: git://github.com/tpope/vim-haml.git | |
" BUNDLE: git://github.com/tpope/vim-surround.git | |
" BUNDLE: git://github.com/tpope/vim-rails.git | |
" BUNDLE: git://github.com/tpope/vim-unimpaired.git | |
" BUNDLE: git://github.com/tpope/vim-endwise.git | |
" BUNDLE: git://github.com/tpope/vim-repeat.git | |
" BUNDLE: git://github.com/tsaleh/vim-align.git | |
" BUNDLE: git://github.com/tsaleh/vim-shoulda.git | |
" BUNDLE: git://github.com/vim-scripts/camelcasemotion.git | |
" BUNDLE: git://github.com/vim-scripts/jQuery.git | |
" BUNDLE: git://github.com/vim-scripts/IndexedSearch.git | |
" BUNDLE: git://github.com/vim-scripts/closetag.vim.git | |
" BUNDLE: git://github.com/vim-scripts/jade.vim.git | |
" BUNDLE: git://github.com/airblade/vim-rooter.git | |
" BUNDLE: git://github.com/mortice/pbcopy.vim.git | |
" BUNDLE: git://github.com/rygwdn/vim-conque.git | |
" Static: suderman | |
" Basic stuff | |
syntax on | |
set hidden | |
set title | |
set visualbell | |
set timeoutlen=500 | |
set scrolloff=3 | |
" Status bar | |
set number | |
set ruler | |
set showcmd | |
set showmode | |
set laststatus=2 | |
" BUNDLE: git://github.com/vim-scripts/buftabs.git | |
let g:buftabs_in_statusline=1 | |
let g:buftabs_only_basename=1 | |
let g:buftabs_active_highlight_group="Visual" | |
" Wild stuff! | |
set wildmenu | |
set wildmode=list:longest,list:full | |
set wildignore+=*.o,*.obj,*.pyc,*.rbc,*.class,.svn,test/fixtures/*,vendor/gems/*,*.DS_STORE,*.db,*.swc,*.tar,*.tgz,.git,public_html/images/**,public_html/upload/**,var/**,*/uploads/**,*/pear/** | |
" Encoding | |
set bomb | |
set encoding=utf-8 | |
" Whitespace | |
set nowrap | |
set tabstop=2 | |
set shiftwidth=2 | |
set softtabstop=2 | |
set expandtab | |
set list listchars=tab:\ \ ,trail:· | |
set backspace=indent,eol,start | |
" BUNDLE: git://github.com/godlygeek/csapprox.git | |
colorscheme ir_black | |
set background=dark | |
nmap ;c :colorscheme | |
" BUNDLE: git://github.com/vim-scripts/ScrollColors.git | |
nmap ;cc :COLORSCROLL<CR> | |
" BUNDLE: git://github.com/bzx/vim-theme-pack.git | |
" BUNDLE: git://github.com/altercation/vim-colors-solarized.git | |
let g:solarized_contrast="high" | |
call togglebg#map(";b") | |
" Use modeline overrides | |
set modeline | |
set modelines=10 | |
" Directories for swp files | |
set backupdir=~/.vim/backup | |
set directory=~/.vim/backup | |
set nobackup | |
set nowritebackup | |
" Remember last location in file | |
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif | |
" Visually select the text that was last edited/pasted | |
nmap gV `[v`] | |
" Let split windows be different sizes | |
set noequalalways | |
" Split shortcuts | |
nmap <leader>- :sp<CR> | |
nmap <leader>= :vs<CR> | |
nmap <leader>c :close<CR> | |
nmap <leader>cc :tabclose<CR> | |
" BUNDLE: git://github.com/roman/golden-ratio.git | |
let g:golden_ratio_autocommand = 0 | |
nmap ;g :GoldenRatioToggle<CR> | |
" Smart way to move between windows. Ctrl-[h,j,k,l] | |
nmap <C-j> <C-W>j | |
nmap <C-k> <C-W>k | |
nmap <C-h> <C-W>h | |
nmap <C-l> <C-W>l | |
" If in Visual Mode, resize window instead of changing focus. Ctrl-[h,j,k,l] | |
vmap <C-j> <C-W>+ | |
vmap <C-k> <C-W>- | |
vmap <C-h> <C-W>< | |
vmap <C-l> <C-W>> | |
" Actually move current window | |
nmap <leader>j <C-W><S-j> | |
nmap <leader>k <C-W><S-k> | |
nmap <leader>h <C-W><S-h> | |
nmap <leader>l <C-W><S-l> | |
" Let directional keys work in Insert Mode. Ctrl-[h,j,k,l] | |
imap <C-j> <Esc>ja | |
imap <C-k> <Esc>ka | |
imap <C-h> <Esc>ha | |
imap <C-l> <Esc>la | |
" Cursor movement in command mode | |
cmap <C-j> <Down> | |
cmap <C-k> <Up> | |
cmap <C-h> <Left> | |
cmap <C-l> <Right> | |
cmap <C-x> <Del> | |
cmap <C-z> <BS> | |
cmap <C-v> <C-R>" | |
" 0 is beginning of line, so make - the end of the line | |
nmap - $ | |
" Bubble multiple lines (unimpaired.vim) | |
vmap _ [egv | |
vmap + ]egv | |
" Visual shifting (builtin-repeat) | |
vnoremap < <gv | |
vnoremap > >gv | |
" Searching | |
set hlsearch | |
set incsearch | |
set ignorecase | |
set smartcase | |
" % to bounce from do to end etc. | |
runtime! macros/matchit.vim | |
" Clear search with comma-space | |
nnoremap <leader><space> :noh<cr> | |
" BUNDLE: git://github.com/mileszs/ack.vim.git | |
" Use Ack instead of Grep when available | |
if executable("ack") | |
set grepprg=ack\ -H\ --nogroup\ --nocolor | |
nnoremap <leader>a :Ack | |
cabbrev ack Ack | |
endif | |
" BUNDLE: git://github.com/tpope/vim-markdown.git | |
" BUNDLE: git://github.com/robgleeson/hammer.vim.git | |
function! s:setupWrapping() | |
set wrap | |
set wrapmargin=2 | |
set textwidth=72 | |
endfunction | |
function! s:setupMarkup() | |
call s:setupWrapping() | |
map <buffer> <Leader>m :Mm <CR> | |
endfunction | |
" special filetype syntax coloring | |
au Bufread,BufNewFile {ssh-config} set ft=sshconfig | |
au Bufread,BufNewFile {.rvmrc,rvmrc} set ft=sh | |
au Bufread,BufNewFile {.gitconfig,gitconfig} set ft=gitconfig | |
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby | |
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup() | |
au BufRead,BufNewFile *.txt call s:setupWrapping() | |
" make python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ ) | |
au FileType python set tabstop=4 textwidth=79 | |
" load the plugin and indent settings for the detected filetype | |
filetype plugin indent on | |
" BUNDLE: git://github.com/scrooloose/syntastic.git | |
let g:syntastic_enable_signs=1 | |
let g:syntastic_quiet_warnings=1 | |
" BUNDLE: git://github.com/kchmck/vim-coffee-script.git | |
au BufWritePost *.coffee silent CoffeeMake! -b | cwindow | redraw! | |
au BufNewFile,BufReadPost *.coffee setl foldmethod=indent nofoldenable | |
" BUNDLE: git://github.com/rgarver/Kwbd.vim.git | |
" :bd deletes a buffer, :BD deletes a buffer and keeps its window | |
command! BD Kwbd | |
" Don't save, close buffer, keep window | |
nmap ZX :BD<CR> | |
" Don't save, close buffer, close window | |
nmap ZXX :bd!<CR> | |
" Save, close buffer, keep window | |
nmap ZSX :w<CR>:BD<CR> | |
" Save, close buffer, close window | |
nmap ZSXX :w<CR>:bd!<CR> | |
" Save the buffer | |
nmap ZS :w<CR> | |
nmap <leader>w :w<CR> | |
" Quit | |
nmap <leader>q :q<CR> | |
nmap <leader>qq :q!<CR> | |
nmap <leader>qqq :qa!<CR> | |
" BUNDLE: git://github.com/vim-scripts/bufexplorer.zip.git | |
command! Buffers call s:Buffers() | |
function! s:Buffers() | |
let l:title = expand("%:t") | |
if (l:title == '[BufExplorer]') | |
:b# | |
else | |
:silent BufExplorer | |
endif | |
endfunction | |
nmap <S-k> :Buffers<CR> | |
nmap <S-h> :tabprevious<CR> | |
nmap <S-l> :tabnext<CR> | |
nmap <leader>t :tabnew<CR> | |
nmap ;t :tab ball<CR> | |
set tabpagemax=50 | |
" Cycle buffers | |
map <S-tab> :bnext<CR> | |
" Quick access to command mode | |
map ;; : | |
" BUNDLE: git://github.com/vim-scripts/ZoomWin.git | |
map <Leader><Leader> :ZoomWin<CR> | |
" F5 will remove trailing whitespace and tabs | |
nnoremap <silent> <F5> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>:retab<CR> | |
" Opens an edit command with the path of the currently edited file filled in | |
map :ee :e <C-R>=expand("%:p:h") . "/" <CR> | |
" ;cd to current file | |
nnoremap ;cd :cd %:p:h<CR>:pwd<CR> | |
" Alt-tab between buffers with comma-comma-tab (,,Tab) | |
nmap <leader>6 <C-^> | |
nmap <leader>^ <C-^> | |
map <M-tab>: <C-^> | |
" When pasting from OS's clipboard, hit ,P command-v ,P | |
nnoremap <leader>p :set invpaste paste?<CR> | |
set pastetoggle=<leader>p | |
" BUNDLE: git://github.com/vim-scripts/YankRing.vim.git | |
nnoremap <silent> [p :YRShow<cr> | |
inoremap <silent> [p <ESC>:YRShow<cr> | |
let g:yankring_history_file = '.yankring_history' | |
" BUNDLE: git://github.com/scrooloose/nerdtree.git | |
" Static: nerdtree-extra | |
" NERDTree toggles with ,d | |
map <Leader>d :NERDTreeToggle<CR> | |
map <Leader>dd :NERDTreeRefresh<CR>:NERDTreeFind<CR> | |
let NERDTreeIgnore=['\.rbc$', '\~$'] | |
let NERDTreeDirArrows=1 | |
let NERDTreeMinimalUI=1 | |
let NERDTreeShowHidden=1 | |
" BUNDLE: git://git.wincent.com/command-t.git | |
" BUNDLE-COMMAND: if which rvm >/dev/null 2>&1; then rvm system exec rake make; else rake make; fi | |
" Command-T works with ,g --> [G]o-To-File | |
map <Leader>g :CommandT<CR> | |
let g:CommandTMaxHeight=20 | |
let g:CommandTCancelMap = ['<C-c>', '<Esc>'] | |
" u is undo, so make ctrl-u redo (don't need 'undo line' anyway...) | |
nmap U <C-R> | |
" BUNDLE: git://github.com/sjl/gundo.vim.git | |
" ,u will show undo history graph | |
nnoremap <leader>u :GundoToggle<CR> | |
let g:gundo_right = 1 | |
" BUNDLE: git://github.com/mattn/gist-vim.git | |
let g:gist_detect_filetype = 1 | |
let g:gist_open_browser_after_post = 1 | |
if has("mac") | |
let g:gist_clip_command = 'pbcopy' | |
elseif has("unix") | |
let g:gist_clip_command = 'xclip -selection clipboard' | |
endif | |
" Pressing ,ss will toggle and untoggle spell checking | |
map <leader>ss :setlocal spell!<CR> | |
" Move to the next misspelled word | |
map <leader>sn ]s | |
" Move to the previous misspelled word | |
map <leader>sp [s | |
" Add word to dictionary | |
map <leader>sa zg | |
" View spelling suggestions for misspelled word | |
map <leader>s? z= | |
" BUNDLE: git://github.com/sophacles/vim-bundle-sparkup.git | |
" Location of the sparkup executable. Seems to finding it in the same dir as the vim script. | |
let g:sparkup = 'sparkup' | |
" Additional args passed to sparkup. | |
let g:sparkupArgs = '--no-last-newline' | |
" Mapping used to execute sparkup. | |
let g:sparkupExecuteMapping = '<c-e>' | |
" Mapping used to jump to the next empty tag/attribute (leaving this as <c-n> breaks tab-completion) | |
let g:sparkupNextMapping = '<c-x>' | |
nmap <leader>r :SearchReplace<CR> | |
nmap <leader>rr :SearchReplaceLast<CR> | |
" Given a full path to a file, this will set the following variables: | |
" path, file, filename, extension | |
function! s:ParseFilePath() | |
let s:path=expand("%:p") | |
let l:array = split(s:path,"/") | |
let l:arraylen = len(l:array) | |
let l:id = l:arraylen - 1 | |
let s:file = l:array[l:id] | |
call remove(l:array, l:id) | |
let s:path = "/" . join(l:array, "/") . "/" | |
let l:array = split(s:file,'\.') | |
let l:arraylen = len(l:array) | |
let l:id = l:arraylen - 1 | |
let s:extension = l:array[l:id] | |
call remove(l:array, l:id) | |
let s:filename = join(l:array, ".") | |
endfunction | |
command! SearchFile let q = input("Search within this file: ") | exe "/".q."/" | |
command! SearchProject let q = input("Search within this project: ") | exe ":Ack -a ".q | |
command! SearchReplace let q = input("Search within this file: ") | let r = input("...and replace with this: ") | exe ":%s/".q."/".r."/g" | |
command! SearchReplaceLast let r = input("Replace last search with this: ") | exe ":%s//".r."/g" | |
command! NewFile call s:NewFile() | |
function! s:NewFile() | |
call s:ParseFilePath() | |
" Prompt for new filename | |
execute "let newfilename=input('New file: ','". s:path . "')" | |
" Create and open new file | |
silent execute ':!touch "' . newfilename .'"' | redraw! | |
execute ':e '. newfilename | |
call s:UpdateNERDTree() | |
endfunction | |
command! SaveAs call s:SaveAs() | |
function! s:SaveAs() | |
call s:ParseFilePath() | |
" Prompt for new filename | |
execute "let newfilename=input('Save as: ','". s:path . s:filename . "-copy." . s:extension . "')" | |
" Make copy of old file into new file | |
silent execute ':!cp % "' . newfilename .'"' | redraw! | |
execute ':e '. newfilename | |
call s:UpdateNERDTree() | |
endfunction | |
command! RenameFile call s:RenameFile() | |
function! s:RenameFile() | |
call s:ParseFilePath() | |
" Prompt for new filename | |
execute "let newfilename=input('Rename file: ','". s:path . s:file . "')" | |
" Make copy of old file into new file | |
silent execute ':!mv % "' . newfilename .'"' | redraw! | |
execute ':e '. newfilename | |
call s:UpdateNERDTree() | |
echo "File renamed!" | |
endfunction | |
command! RemoveFile call s:RemoveFile() | |
function! s:RemoveFile() | |
execute ':!rm -i %' | |
silent redraw! | |
call s:UpdateNERDTree() | |
endfunction | |
command! NewSplit call s:NewSplit() | |
function! s:NewSplit() | |
let l:height=winheight(0) * 2 | |
let l:width=winwidth(0) - 4 | |
if (l:height > l:width) | |
:new | |
else | |
:vnew | |
endif | |
endfunction | |
" Launch vimrc with ,v and automatically load changes on write | |
autocmd bufwritepost .vimrc source ~/.vimrc | |
nmap <leader>v :EditVimRC<CR> | |
command! EditVimRC call s:EditVimRC() | |
function! s:EditVimRC() | |
let l:title = expand("%:t") | |
if (l:title == '.vimrc') | |
:edit ~/.gvimrc | |
else | |
:edit ~/.vimrc | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment