Created
September 12, 2012 00:50
-
-
Save stechz/3703356 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
fun! FactorEvalInput(string) | |
execute "normal a" . a:string | |
normal `[v`]hd | |
return @" | |
endfun | |
fun! FactorWrite() range | |
if s:factorWrite | |
iunmap <ESC> | |
augroup factor | |
au! InsertLeave <buffer> | |
augroup end | |
let cursor = getpos(".") | |
let s:factorWrite = 0 | |
let stmt = @" | |
let varName = FactorEvalInput(@.) | |
if match(varName, "\\s*[a-zA-Z_][a-zA-Z0-9]*") == 0 | |
let varName = substitute(varName, "\\s+", "", "") | |
let varName = substitute(varName, "[^a-zA-Z0-9_].*", "", "") | |
execute "normal Ovar " . varName . " = " . stmt . ";" | |
endif | |
let cursor[1] = cursor[1] + 1 | |
call setpos(".", cursor) | |
endif | |
endfun | |
fun! Factor() range | |
normal gvd | |
normal `< | |
let s:factorWrite = 1 | |
inoremap <silent> <ESC> <ESC>:call FactorWrite()<CR> | |
augroup factor | |
autocmd! | |
autocmd InsertLeave <buffer> call FactorWrite() | |
augroup end | |
startinsert | |
endfun | |
fun! FactorSelect() range | |
execute "normal /,\\|)\<CR>hv?,\\|(\<CR>/\\S\<CR>" | |
endfun | |
nmap ,f :call FactorSelect()<CR> | |
vmap ,f :call Factor()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this to break down dense or long lines of Javascript by replacing inline expressions with a variable set to that expression.
Enjoy!