Created
June 18, 2013 20:21
-
-
Save tskogberg/5808975 to your computer and use it in GitHub Desktop.
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
" Promote variable to RSpec let. | |
" Based on | |
" https://github.com/myronmarston/vim_files/commit/ed60919f1857359da617491a7d7c14e8d4befae0 | |
" | |
" Given either of | |
" | |
" foo = x | |
" @foo = x | |
" | |
" on the current line or in a given range (e.g. visual range), | |
" this command moves the assignments out to an RSpec let: | |
" | |
" let(:foo) { x } | |
" | |
function! s:PromoteToLet() | |
let current_line = getline('.') | |
let equals = '@\?\w\+ = .*$' | |
let let = 'let(:\w\+)\s{\s.*\s}$' | |
if current_line =~ equals | |
.s/@\?\(\w\+\) = \(.*\)$/let(:\1) { \2 }/ | |
elseif current_line =~ let | |
.s/let(:\(\w\+\))\s{\s\(.*\)\s}$/\1 = \2/ | |
else | |
echom 'no match' | |
endif | |
endfunction | |
command! -range Let execute '<line1>,<line2>call <SID>PromoteToLet()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment