Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " Stefan Schmidt's .vimrc
- " http://github.com/schlubbi
- "
- " thanks to Gary Bernhardt https://github.com/garybernhardt
- set t_Co=256
- set nocompatible " Must come first because it changes other options.
- silent! call pathogen#runtime_append_all_bundles()
- syntax on " Turn on syntax highlighting.
- filetype plugin indent on " Turn on file type detection.
- runtime macros/matchit.vim " Load the matchit plugin.
- set showcmd " Display incomplete commands.
- set showmode " Display the mode you're in.
- set backspace=indent,eol,start " Intuitive backspacing.
- set hidden " Handle multiple buffers better.
- set wildmenu " Enhanced command line completion.
- set wildmode=longest,list " complete files like a shell.
- set ignorecase " Case-insensitive searching.
- set smartcase " But case-sensitive if expression contains a capital letter.
- set number " Show line numbers.
- set ruler " Show cursor position.
- set incsearch " Highlight matches as you type.
- set hlsearch " Highlight matches.
- set wrap " Turn on line wrapping.
- set scrolloff=3 " Show 3 lines of context around the cursor.
- set title " Set the terminal's title
- set visualbell " No beeping.
- set cursorline
- set nobackup " Don't make a backup before overwriting a file.
- set nowritebackup " And again.
- set cmdheight=2
- set tabstop=2 " Global tab width.
- set shiftwidth=2 " And again, related.
- set expandtab " Use spaces instead of tabs
- set numberwidth=5
- set showtabline=2
- set winwidth=79
- " Store temporary files in a central spot
- set backup
- set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
- set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
- " This makes RVM work inside Vim. I have no idea why.
- set shell=/bin/sh
- set laststatus=2 " Show the status line all the time
- " Useful status information at bottom of screen
- set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{fugitive#statusline()}%{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P
- " Prevent Vim from clobbering the scrollback buffer. See
- " http://www.shallowsky.com/linux/noaltscreen.html
- set t_ti= t_te=
- " keep more context when scrolling off the end of a buffer
- set scrolloff=3
- "Color Settings
- "colorscheme railscasts
- " set t_Co=256
- " set background=dark
- " color solarized
- " color codeschool
- " solarized options
- let g:solarized_termcolors = 256
- let g:solarized_visibility = "high"
- let g:solarized_contrast = "high"
- colorscheme solarized
- " Map leader key to ','
- let mapleader=","
- set guifont=Monaco:h12
- let g:NERDTreeWinPos = "right"
- set guioptions-=T " Removes top toolbar
- set guioptions-=r " Removes right hand scroll bar
- set go-=L " Removes left hand scroll bar
- " keep longer history
- set history=1000
- " Make the current window big, but leave others context
- set winwidth=84
- " We have to have a winheight bigger than we want to set winminheight. But if
- " we set winheight to be huge before winminheight, the winminheight set will
- " fail.
- set winheight=5
- set winminheight=5
- set winheight=999
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " KEY MAPPINGS
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " Insert a hash rocket with <c-l>
- imap <c-l> <space>=><space>
- " Clear the search buffer when hitting return
- function! MapCR()
- nnoremap <cr> :nohlsearch<cr>
- endfunction
- call MapCR()
- nnoremap <leader><leader> <c-^>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " MULTIPURPOSE TAB KEY
- " " Indent if we're at the beginning of a line. Else, do completion.
- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- "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>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " ARROW KEYS ARE UNACCEPTABLE
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- map <Left> <Nop>
- map <Right> <Nop>
- map <Up> <Nop>
- map <Down> <Nop>
- " Edit or view files in same directory as current file
- cnoremap %% <C-R>=expand('%:h').'/'<cr>
- map <leader>e :edit %%
- map <leader>v :view %%
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " RENAME CURRENT FILE
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- 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>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " PROMOTE VARIABLE TO RSPEC LET
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- function! PromoteToLet()
- :normal! dd
- " :exec '?^\s*it\>'
- :normal! P
- :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
- :normal ==
- endfunction
- :command! PromoteToLet :call PromoteToLet()
- :map <leader>p :PromoteToLet<cr>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " COMMAND-T CONFIG
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- map <leader>gr :topleft :split config/routes.rb<cr>
- function! ShowRoutes()
- " Requires 'scratch' plugin
- :topleft 100 :split __Routes__
- " Make sure Vim doesn't write __Routes__ as a file
- :set buftype=nofile
- " Delete everything
- :normal 1GdG
- " Put routes output in buffer
- :0r! bundle exec rake -s routes
- " Size window to number of lines (1 plus rake output length)
- :exec ":normal " . line("$") . _ "
- " Move cursor to bottom
- :normal 1GG
- " Delete empty trailing line
- :normal dd
- endfunction
- map <leader>gR :call ShowRoutes()<cr>
- let g:CommandTCancelMap=['<ESC>','<C-c>']
- " Open files with <leader>f
- map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
- " Open files, limited to the directory of the current file, with <leader>gf
- " This requires the %% mapping found below.
- map <leader>F :CommandTFlush<cr>\|:CommandT %%<cr>
- " Custom Rails-specific Command-T mappings
- map <leader>gv :CommandTFlush<cr>\|:CommandT app/views<cr>
- map <leader>gc :CommandTFlush<cr>\|:CommandT app/controllers<cr>
- map <leader>gm :CommandTFlush<cr>\|:CommandT app/models<cr>
- map <leader>gh :CommandTFlush<cr>\|:CommandT app/helpers<cr>
- map <leader>gl :CommandTFlush<cr>\|:CommandT lib<cr>
- map <leader>gp :CommandTFlush<cr>\|:CommandT public<cr>
- map <leader>gs :CommandTFlush<cr>\|:CommandT public/stylesheets<cr>
- " Other Rails-specific file keystrokes
- map <leader>gg :topleft 100 :split Gemfile<cr>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " CUSTOM AUTOCMDS
- " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- augroup vimrcEx
- " Clear all autocmds in the group
- autocmd!
- autocmd FileType text setlocal textwidth=78
- " Jump to last cursor position unless it's invalid or in an event handler
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line("'\"") <= line("$") |
- \ exe "normal g`\"" |
- \ endif
- " for ruby, autoindent with two spaces, always expand tabs
- autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
- autocmd FileType python set sw=4 sts=4 et
- autocmd! BufRead,BufNewFile *.sass setfiletype sass
- " Indent p tags
- autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
- " Leave the return key alone when in command line windows, since it's used
- " to run commands there.
- autocmd! CmdwinEnter * :unmap <cr>
- autocmd! CmdwinLeave * :call MapCR()
- augroup END
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " SWITCH BETWEEN TEST AND PRODUCTION CODE
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- function! OpenTestAlternate()
- let new_file = AlternateForCurrentFile()
- exec ':e ' . new_file
- endfunction
- function! AlternateForCurrentFile()
- let current_file = expand("%")
- let new_file = current_file
- let in_spec = match(current_file, '^spec/') != -1
- let going_to_spec = !in_spec
- let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1
- if going_to_spec
- if in_app
- let new_file = substitute(new_file, '^app/', '', '')
- end
- let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
- let new_file = 'spec/' . new_file
- else
- let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
- let new_file = substitute(new_file, '^spec/', '', '')
- if in_app
- let new_file = 'app/' . new_file
- end
- endif
- return new_file
- endfunction
- nnoremap <leader>. :call OpenTestAlternate()<cr>
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " RUNNING TESTS
- """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- map <leader>t :call RunTestFile()<cr>
- map <leader>T :call RunNearestTest()<cr>
- map <leader>a :call RunTests('')<cr>
- map <leader>c :w\|:!script/features<cr>
- map <leader>w :w\|:!script/features --profile wip<cr>
- 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\)$') != -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
- function! SetTestFile()
- " Set the spec file that tests will be run for.
- let t:grb_test_file=@%
- endfunction
- function! RunTests(filename)
- " Write the file and run tests for the given filename
- :w
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
- if match(a:filename, '\.feature$') != -1
- exec ":!script/features " . 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement