Created
April 12, 2020 20:51
-
-
Save timjstewart/f54e0dfba2435d81bc3836c7e60b90f3 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
function! ReplaceMagicWithConstant(Arg, Start, Stop) | |
let constantName = input("Enter Constant Name: ") | |
call append(line("'<") - 1, printf("%s = %s", l:constantName, a:Arg)) | |
execute printf("'<, '>s/%s/%s/gc", a:Arg, l:constantName) | |
endfunction | |
function! CandidateMagic(ArgLead, CmdLine, CursorPos) | |
let allWords = uniq(sort(split(join(getline("'<", "'>")), '\W\+'))) | |
call filter(allWords, {idx, val -> -1 != stridx(val, a:ArgLead)}) | |
return allWords | |
endfunction | |
command! -range=% -complete=customlist,CandidateMagic -nargs=1 ReplaceMagicWithConstant call ReplaceMagicWithConstant("<args>", <line1>, <line2>) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment