Skip to content

Instantly share code, notes, and snippets.

@jakecraige
Created August 8, 2013 12:38
Show Gist options
  • Save jakecraige/6184218 to your computer and use it in GitHub Desktop.
Save jakecraige/6184218 to your computer and use it in GitHub Desktop.
"Jake Craige
" place this file in your home dir
" must install vundle in ~/.vim/bundle/ first.
" Then open up vim and type :BundleInstall
" and you should be good to go!
" Setup {{{
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" My Bundles here:
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-endwise'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-sensible'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-unimpaired'
Bundle 'jakecraige/vim-colors'
Bundle 'thingsinjars/Cobalt.vim'
Bundle 'altercation/vim-colors-solarized'
Bundle 'sjl/badwolf'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'kien/ctrlp.vim'
Bundle 'godlygeek/tabular'
" webapi required for gits
Bundle 'mattn/webapi-vim'
Bundle 'mattn/gist-vim'
Bundle 'othree/javascript-libraries-syntax.vim'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
Bundle 'scrooloose/syntastic'
Bundle 'spf13/PIV'
Bundle 'msanders/snipmate.vim'
Bundle 'vim-scripts/TaskList.vim'
Bundle 'vim-scripts/taglist.vim'
Bundle 'Townk/vim-autoclose'
Bundle 'kchmck/vim-coffee-script'
Bundle 'hail2u/vim-css3-syntax'
Bundle 'nathanaelkane/vim-indent-guides'
Bundle "pangloss/vim-javascript"
Bundle 'duff/vim-scratch'
filetype plugin indent on
" }}}
" Language Specific {{{
" Javascript {{{
autocmd BufReadPre *.coffee let b:javascript_lib_use_angularjs = 1
" Compile coffee files automatically on sav - add | redraw! for terminal
"au BufWritePost *.coffee silent CoffeeMake! -b | cwindow
" }}}
" Rails {{{
map <Leader>rm :Rmodel<cr>
map <Leader>rc :Rcontroller<cr>
" }}}
" Ruby {{{
augroup ft_ruby
au!
au Filetype ruby setlocal foldmethod=syntax
augroup END
" }}}
" Vim {{{
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
au FileType help setlocal textwidth=78
au BufWinEnter *.txt if &ft == 'help' | wincmd L | endif
augroup END
" }}}
" }}}
" General make life easy settings {{{
let mapleader = ","
set noesckeys
set mouse=a
set mousehide
set nocompatible
set autoindent
set modelines=0
set scrolljump=5
set scrolloff=3
set showmode
set showcmd
set hidden
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast " fast scrolling...
set list
set relativenumber
set foldenable " enable code folding
set virtualedit=onemore " Allow cursor beyondlast character
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids
set colorcolumn=+1
set linebreak
set title
set shiftround
set splitbelow
set splitright
set undofile
set undoreload=10000
set history=1000
set laststatus=2
set matchtime=3
command! Q q " Bind :Q to :q
command! Qall qall
" Disable Ex mode
map Q <nop>
" }}}
" Make Life Easy Bindings {{{
" S in normal mode to split line, sister to J
nnoremap S i<cr><esc><right>
" Post to gist and copy in clipboard
vnoremap <leader>G :w !gist -p -t %:e \| pbcopy<cr>
"For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
"Adjust viewports to the same size
map <Leader>= <C-w>=
"Rehighlight pasted text
nnoremap <leader>v V`]
"Save a keystroke
nnoremap ; :
"Bind jj to ESC for quicker switching modes
inoremap jj <ESC>
" 0 now goes to first char in line instead of blank"
nnoremap 0 0^
" }}}
" Folding {{{
" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za
" Make zO recursively open whatever top level fold we're in, no matter where the
" cursor happens to be.
nnoremap zO zCzO
function! MyFoldText() " {{{
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction " }}}
set foldtext=MyFoldText()
" }}}
" Colorscheme, Gui, Font {{{
"Status line with fugitive git integration
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
if has('gui_running')
colorscheme cobalt
" removes scrollbar and toolbar"
set guioptions+=lrb
set guioptions-=lrb " Remove the toolbar
set guioptions-=T
set lines=40 " 40 lines of text instead of 24
else
"set background=dark
"colorscheme solarized
colorscheme molokai
"colorscheme badwolf
"colorscheme ir_black
endif
" Font , Text, Tabs {{{
" Auto format comment blocks
set comments=sl:/*,mb:*,elx:*/
set guifont=Inconsolata\ 13
"Set tabs to 2 spaces instead of the default 4
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
"Text wrapping
set wrap
set textwidth=80
set formatoptions=qrn1
set colorcolumn=+1
" }}}
" }}}
" Quick Edit Common Files{{{
nnoremap <leader>ev <C-w><C-v><C-l>:e ~/.vimrc<cr>
nnoremap <leader>ez <C-w><C-v><C-l>:e ~/.zshrc<cr>
nnoremap <Leader>sn :e ~/.vim/bundle/snipmate.vim/snippets<CR>
"}}}
" File Editing {{{
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
map <Leader>e :e <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>s :split <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>v :vnew <C-R>=expand("%:p:h") . '/'<CR>
map <leader><tab> :Scratch<CR>
" RENAME CURRENT FILE (thanks Gary Bernhardt) {{{
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <Leader>n :call RenameFile()<cr>
" }}}
" Line Return On File Open{{{
" Make sure Vim returns to the same line when you reopen a file.
" Thanks, Amit
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" }}}
" }}}
" Navigation {{{
" Change Working Directory to that of the current file
cmap cwd lcd %:p:h
cmap cd. lcd %:p:h
"Visual shifting (does not exit Visual mode on tab)
vnoremap < <gv
vnoremap > >gv
"Movement - better Navigation
nnoremap j gj
nnoremap k gk
nnoremap k gk
"Split Window Navigation mapping
nnoremap <leader>w <C-w>v<C-w>l
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" }}}
" Searching {{{
"Fix broken searching by enabling regular regex I think?
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set gdefault " assume the /g flag on :s substitutions to replace all matches in a line
set hlsearch
" highlighted in visual mode, any in normal
nnoremap <leader>r :%s//gc<left><left><left>
nnoremap <leader>ra :%s//g<left><left>
vnoremap <leader>r "hy:%s/<C-r>h//gc<left><left><left>
vnoremap <leader>ra "hy:%s/<C-r>h//g<left><left>
"Undo highlignted searches
nnoremap <leader><space> :noh<cr>
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
nnoremap <c-o> <c-o>zz
" Don't move on *
nnoremap * *<c-o>
" Visual Mode */# from Scrooloose {{{
" Lets you use * in visual mode
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" }}}
" }}}
" Git Setup {{{
map <Leader>gac :Gcommit -m -a ""<LEFT>
map <Leader>gc :Gcommit -m ""<LEFT>
map <Leader>gs :Gstatus<CR>
map <Leader>gw :!git add . && git commit -m 'WIP' && git push<cr>
" }}}
" Select all, copy, go back to where you were, and duplicate {{{
"map <Leader>a ggVGy<C-o><C-o>
map <Leader>d y'>p
map <Leader>c :sh<CR>
" }}}
" Backups {{{
set backup " enable backups
set noswapfile " it's 2013, Vim.
set undodir=~/.vim/tmp/undo// " undo files
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
" Make those folders automatically if they don't already exist.
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
" }}}
" Plugins {{{
" NERDTree {{{
map <C-e> :NERDTreeToggle<CR>
let NERDTreeHighlightCursorline = 1
let NERDTreeIgnore = ['.vim$', '\~$', '.*\.pyc$', 'pip-log\.txt$', 'whoosh_index',
\ 'xapian_index', '.*.pid', 'monitor.py', '.*-fixtures-.*.json',
\ '.*\.o$', 'db.db', 'tags.bak', '.*\.pdf$', '.*\.mid$',
\ '.*\.midi$']
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
let NERDChristmasTree = 1
let NERDTreeChDirMode = 2
let NERDTreeMapJumpFirstChild = 'gK'
" }}}
" taglist.vim {{{
let Tlist_Use_Right_Window=1
let Tlist_Auto_Open=0
let Tlist_Enable_Fold_Column=0
let Tlist_Compact_Format=0
let Tlist_WinWidth=28
let Tlist_Exit_OnlyWindow=1
let Tlist_File_Fold_Auto_Close = 1
nmap <leader>tl :Tlist<cr>
" }}}
" Task List {{{
" Add DEV to list of tokens
let g:tlTokenList = ['FIXME', 'TODO', 'DEV']
"}}}
" Sparkup {{{
let g:sparkupExecuteMapping = '<leader>h'
" }}}
" Tabular {{{
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
" }}}
" }}}
" Uncategorized {{{
" Panic Button, haha..
nnoremap <f9> mzggg?G`z
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment