Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
152 lines (134 sloc) 3.88 KB
" ----------------------------------------
" Functions
" ----------------------------------------
" ---------------
" Convert Ruby 1.8 hash rockets to 1.9 JSON style hashes.
" From: http://git.io/cxmJDw
" Note: Defaults to the entire file unless in visual mode.
" ---------------
command! -bar -range=% NotRocket execute '<line1>,<line2>s/:\(\w\+\)\s*=>/\1:/e' . (&gdefault ? '' : 'g')
" ---------------
" Strip Trailing White Space
" ---------------
" From http://vimbits.com/bits/377
" Preserves/Saves the state, executes a command, and returns to the saved state
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
"strip all trailing white space
command! StripTrailingWhiteSpace :call Preserve("%s/\\s\\+$//e")<CR>
" ---------------
" Quick spelling fix (first item in z= list)
" ---------------
function! QuickSpellingFix()
if &spell
normal 1z=
else
" Enable spelling mode and do the correction
set spell
normal 1z=
set nospell
endif
endfunction
command! QuickSpellingFix call QuickSpellingFix()
" ---------------
" Convert Ruby 1.8 hash rockets to 1.9 JSON style hashes.
" From: http://git.io/cxmJDw
" Note: Defaults to the entire file unless in visual mode.
" ---------------
command! -bar -range=% NotRocket execute '<line1>,<line2>s/:\(\w\+\)\s*=>/\1:/e' . (&gdefault ? '' : 'g')
" ---------------
" Strip Trailing White Space
" ---------------
" From http://vimbits.com/bits/377
" Preserves/Saves the state, executes a command, and returns to the saved state
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
"strip all trailing white space
command! StripTrailingWhiteSpace :call Preserve("%s/\\s\\+$//e")<CR>
" ---------------
" Ack
" ---------------
" Find current word in command mode
function! AckGrep()
let command = "ack ".expand("<cword>")
cexpr system(command)
cw
endfunction
function! AckVisual()
normal gv"xy
let command = "ack ".@x
cexpr system(command)
cw
endfunction
" ---------------
" Tests
" ---------------
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.go\)$') != -1
if in_test_file
call RunTests(expand("%") . command_suffix)
else
call RunTests('')
end
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
let s:last_command = ":" . spec_line_number
call RunTestFile(":" . spec_line_number)
endfunction
function! RunTests(filename)
:wa
if a:filename == ''
call vipe#peek()
return
endif
let command = ''
if match(a:filename, '\.feature') != -1
if filereadable("script/features")
let command = "script/features " . a:filename
elseif filereadable("Gemfile")
let command = "bundle exec cucumber " . a:filename
else
let command = "cucumber " . a:filename
end
elseif match(a:filename, '_test\.go') != -1
if filereadable("script/test")
let command = "script/test " . fnamemodify(a:filename, ':h')
else
let command = "ginkgo " . fnamemodify(a:filename, ':h')
end
else
if filereadable("script/test")
let command = "script/test " . a:filename
elseif (exists('g:force_bundle_exec') && g:force_bundle_exec == 1) || filereadable("Gemfile")
let command = "bundle exec rspec --color " . a:filename
else
let command = "rspec --color " . a:filename
end
end
call vipe#push(command)
endfunction