Created
March 26, 2014 15:04
-
-
Save aghyad/9785440 to your computer and use it in GitHub Desktop.
.vimrc
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
" .vimrc | |
" load up pathogen and all bundles | |
syntax on " show syntax highlighting | |
filetype plugin indent on | |
set autoindent " set auto indent | |
set ts=2 " set indent to 2 spaces | |
set shiftwidth=2 | |
set expandtab " use spaces, not tab characters | |
set nocompatible " don't need to be compatible with old vim | |
set relativenumber " show relative line numbers | |
set showmatch " show bracket matches | |
set ignorecase " ignore case in search | |
set hlsearch " highlight all search matches | |
set cursorline " highlight current line | |
set smartcase " pay attention to case when caps are used | |
set incsearch " show search results as I type | |
set mouse=a " enable mouse support | |
set ttimeoutlen=100 " decrease timeout for faster insert with 'O' | |
set vb " enable visual bell (disable audio bell) | |
set ruler " show row and column in footer | |
set scrolloff=2 " minimum lines above/below cursor | |
set laststatus=2 " always show status bar | |
set list listchars=tab:»·,trail:· " show extra space characters | |
" set nofoldenable " disable code folding | |
set clipboard=unnamed " use the system clipboard | |
set wildmenu " enable bash style tab completion | |
set wildmode=list:longest,full | |
" set dark background and color scheme | |
set background=dark | |
" set up some custom colors | |
highlight clear SignColumn | |
highlight VertSplit ctermbg=236 | |
highlight ColorColumn ctermbg=237 | |
highlight LineNr ctermbg=236 ctermfg=240 | |
highlight CursorLineNr ctermbg=236 ctermfg=240 | |
highlight CursorLine ctermbg=236 | |
highlight StatusLineNC ctermbg=238 ctermfg=0 | |
highlight StatusLine ctermbg=240 ctermfg=12 | |
highlight IncSearch ctermbg=0 ctermfg=3 | |
highlight Search ctermbg=0 ctermfg=9 | |
highlight Visual ctermbg=3 ctermfg=0 | |
highlight Pmenu ctermbg=240 ctermfg=12 | |
highlight PmenuSel ctermbg=0 ctermfg=3 | |
highlight SpellBad ctermbg=0 ctermfg=1 | |
" highlight the status bar when in insert mode | |
if version >= 700 | |
au InsertEnter * hi StatusLine ctermfg=235 ctermbg=2 | |
au InsertLeave * hi StatusLine ctermbg=240 ctermfg=12 | |
endif | |
" set leader key to comma | |
let mapleader = "," | |
" ctrlp config | |
let g:ctrlp_map = '<leader>f' | |
let g:ctrlp_max_height = 30 | |
let g:ctrlp_working_path_mode = 0 | |
let g:ctrlp_match_window_reversed = 0 | |
" unmap F1 help | |
nmap <F1> :echo<CR> | |
imap <F1> <C-o>:echo<CR> | |
" map . in visual mode | |
vnoremap . :norm.<cr> | |
" die hash rockets, die! | |
vnoremap <leader>h :s/:\(\w*\) *=>/\1:/g<cr> | |
" delete all trailing whitespace in current file | |
map <leader>w :%s/\s\+$//gce \| w<cr> | |
" delete all trailing whitespace for each file in repo | |
map <leader>W :args `git grep -lI .` \| argdo %s/\s\+$//gce \| w<cr> | |
" map markdown preview | |
map <leader>m :!open -a Marked %<cr><cr> | |
" map git commands | |
map <leader>b :Gblame<cr> | |
map <leader>l :!clear && git log -p %<cr> | |
map <leader>d :!clear && git diff %<cr> | |
map <leader>gitdev :!git add . && git commit -m "wip" && git push origin dev<cr> | |
" check code complexity | |
map <leader>x :!clear && flog %<cr> | |
" open scratchpad | |
map <leader>s :e /Users/chris/Dropbox/Notational\ Data/Scratchpad.txt<cr> | |
" open gist after it's been created | |
let g:gist_open_browser_after_post = 1 | |
" shortcuts for going next/previous in quickfix (for git log spelunking) | |
nmap [q :cprevious<cr> | |
nmap ]q :cnext<cr> | |
" map Silver Searcher | |
map <leader>a :Ag!<space> | |
" clear the command line and search highlighting | |
noremap <C-l> :nohlsearch<CR> | |
" map %% to current directory | |
cnoremap %% <C-R>=expand('%:h').'/'<cr> | |
" toggle spell check with <F5> | |
map <F5> :setlocal spell! spelllang=en_us<cr> | |
imap <F5> <ESC>:setlocal spell! spelllang=en_us<cr> | |
" hint to keep lines short | |
if exists('+colorcolumn') | |
set colorcolumn=80 | |
endif | |
" jump to last position in file | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line("'\"") <= line("$") | | |
\ exe "normal g`\"" | | |
\ endif | |
" multi-purpose tab key (auto-complete) | |
function! InsertTabWrapper() | |
let col = col('.') - 1 | |
if !col || getline('.')[col - 1] !~ '\k' | |
return "\<tab>" | |
else | |
return "\<c-p>" | |
endif | |
endfunction | |
inoremap <tab> <c-r>=InsertTabWrapper()<cr> | |
inoremap <s-tab> <c-n> | |
" rename current file, via Gary Bernhardt | |
function! RenameFile() | |
let old_name = expand('%') | |
let new_name = input('New file name: ', expand('%')) | |
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> | |
" Run specs with ',t' via Gary Bernhardt | |
function! RunTests(filename) | |
" Write the file and run tests for the given filename | |
:w | |
:silent !clear | |
if match(a:filename, '\.feature$') != -1 | |
exec ":!script/features " . a:filename | |
elseif match(a:filename, '_test\.rb$') != -1 | |
exec ":!ruby -Itest " . a:filename | |
else | |
if filereadable("script/test") | |
exec ":!script/test " . a:filename | |
elseif filereadable("Gemfile") | |
exec ":!bundle exec rspec --color " . a:filename | |
else | |
exec ":!rspec --color " . a:filename | |
end | |
end | |
endfunction | |
function! SetTestFile() | |
" Set the spec file that tests will be run for. | |
let t:grb_test_file=@% | |
endfunction | |
function! RunTestFile(...) | |
if a:0 | |
let command_suffix = a:1 | |
else | |
let command_suffix = "" | |
endif | |
" Run the tests for the previously-marked file. | |
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1 | |
if in_test_file | |
call SetTestFile() | |
elseif !exists("t:grb_test_file") | |
return | |
end | |
call RunTests(t:grb_test_file . command_suffix) | |
endfunction | |
function! RunNearestTest() | |
let spec_line_number = line('.') | |
call RunTestFile(":" . spec_line_number . " -b") | |
endfunction | |
" run test runner | |
map <leader>t :call RunTestFile()<cr> | |
map <leader>T :call RunNearestTest()<cr> | |
" setting up Ctrlp.vim | |
set runtimepath^=~/.vim/bundle/ctrlp.vim | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" configuring Vundle and its plugins: | |
set nocompatible " be iMproved | |
filetype off " required! | |
set rtp+=~/.vim/bundle/vundle/ | |
call vundle#rc() | |
" let Vundle manage Vundle | |
" required! | |
" Bundle 'gmarik/vundle' | |
" | |
" My Bundles here: | |
" | |
" original repos on github | |
Bundle 'tpope/vim-fugitive' | |
Bundle 'Lokaltog/vim-easymotion' | |
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} | |
Bundle 'tpope/vim-rails.git' | |
" vim-scripts repos | |
Bundle 'L9' | |
Bundle 'FuzzyFinder' | |
" non github repos | |
Bundle 'git://git.wincent.com/command-t.git' | |
" git repos on your local machine (ie. when working on your own plugin) Bundle 'file:///Users/gmarik/path/to/plugin' | |
Bundle 'mattn/webapi-vim' | |
Bundle 'mattn/gist-vim' | |
Bundle 'rking/ag.vim' | |
Bundle 'motemen/git-vim' | |
Bundle 'scrooloose/nerdtree' | |
" Bundle 'jlanzarotta/bufexplorer' | |
" Bundle 'vim-ruby/vim-ruby' | |
filetype plugin indent on " required! | |
" | |
" Brief help | |
" :BundleList - list configured bundles | |
" :BundleInstall(!) - install(update) bundles | |
" :BundleSearch(!) foo - search(or refresh cache first) for foo | |
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles | |
" | |
" see :h vundle for more details or wiki for FAQ | |
" NOTE: comments after Bundle command are not allowed.. | |
" Gist plugin Github config | |
let g:gist_use_password_in_gitconfig = 1 | |
colorscheme railscasts | |
" set laststatus=2 | |
" set statusline=%{GitBranch()} | |
set splitright | |
set splitbelow | |
" au! BufWritePost .vimrc source % " This line should reload vimrc once updating and saving | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" rspec mappings | |
map <Leader>t :call RunCurrentSpecFile()<CR> | |
map <Leader>s :call RunNearestSpec()<CR> | |
map <Leader>l :call RunLastSpec()<CR> | |
function! RunCurrentSpecFile() | |
if InSpecFile() | |
let l:command = "s " . @% . " -f documentation" | |
call SetLastSpecCommand(l:command) | |
call RunSpecs(l:command) | |
endif | |
endfunction | |
function! RunNearestSpec() | |
if InSpecFile() | |
let l:command = "s " . @% . " -l " . line(".") . " -f documentation" | |
call SetLastSpecCommand(l:command) | |
call RunSpecs(l:command) | |
endif | |
endfunction | |
function! RunLastSpec() | |
if exists("t:last_spec_command") | |
call RunSpecs(t:last_spec_command) | |
endif | |
endfunction | |
function! InSpecFile() | |
return match(expand("%"), "_spec.rb$") != -1 | |
endfunction | |
function! SetLastSpecCommand(command) | |
let t:last_spec_command = a:command | |
endfunction | |
function! RunSpecs(command) | |
execute ":w\|!clear && echo " . a:command . " && echo && " . a:command | |
endfunction | |
" let NERDTreeIgnore = ['\.git[[dir]]', '\.DS_Store', '\.swp', '\.ruby-gemset', '\.idea'] | |
map <Leader>s :w<CR> | |
map <Leader>w <C-w>w | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment