Skip to content

Instantly share code, notes, and snippets.

@skamithi
Last active October 4, 2015 05:27
Show Gist options
  • Save skamithi/2585369 to your computer and use it in GitHub Desktop.
Save skamithi/2585369 to your computer and use it in GitHub Desktop.
my rails related vimrc
runtime bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
syntax on
filetype plugin indent on
set number
set tabstop=2
set shiftwidth=2
set expandtab
set textwidth=80
let g:ackprg="ack-grep -H --nocolor --nogroup --column"
autocmd User Rails silent! Rnavcommand intializer config/initializers -suffix=.rb -glob=**/*
autocmd User Rails silent! Rnavcommand feature features/ -suffix=.feature -glob=**/*
autocmd User Rails silent! Rnavcommand stepdefinition features/step_definitions/ -glob=**/* -suffix=_steps.rb
autocmd User Rails silent! Rnavcommand sass app/assets/stylesheets/ -suffix=.css.sass -glob=*
autocmd User Rails silent! Rnavcommand specmodel spec/models/ -suffix=_spec.rb -default=model() -glob=*
autocmd User Rails silent! Rnavcommand speccontroller spec/controllers/ -suffix=_controller_spec.rb -default=controller() -glob=*
autocmd User Rails silent! Rnavcommand spechelper spec/helpers/ -suffix=_helper_spec.rb -default=controller() -glob=*
autocmd User Rails silent! Rnavcommand specviews spec/views/ -glob=**/* -suffix=.html.haml_spec.rb -default=controller() -glob=*
autocmd User Rails silent! Rnavcommand factory spec/support/factories/ -glob=**/* -suffix=_factory.rb -default=model() -glob=*
" Vim functions to run RSpec and Cucumber on the current file and optionally
" on the spec/scenario under the cursor.
function! RailsScriptIfExists(name)
execute ":Rvm use"
return a:name
endfunction
function! RunSpec(args)
let spec = RailsScriptIfExists("rspec --color -f d")
let cmd = spec . " " . a:args . " " . @%
execute ":! echo " . cmd . " && " . cmd
endfunction
function! RunCucumber(args)
let cucumber = RailsScriptIfExists("cucumber")
let cmd = cucumber . " " . @% . a:args
execute ":! echo " . cmd . " && " . cmd
endfunction
function! RunTestFile(args)
if @% =~ "\.feature$"
call RunCucumber("" . a:args)
elseif @% =~ "\.rb$"
call RunSpec("" . a:args)
end
endfunction
function! RunTest(args)
if @% =~ "\.feature$"
call RunCucumber(":" . line('.') . a:args)
elseif @% =~ "\_spec.rb$"
call RunSpec("-l " . line('.') . a:args)
end
endfunction
map <Leader>; :call RunTest("")<CR>
map <Leader>' :call RunTestFile("")<CR>
" Removes trailing spaces
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
autocmd FileWritePre * :call TrimWhiteSpace()
autocmd FileAppendPre * :call TrimWhiteSpace()
autocmd FilterWritePre * :call TrimWhiteSpace()
autocmd BufWritePre * :call TrimWhiteSpace()
"always show filename at the bottom of the terminal
set modeline
set ls=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment