Skip to content

Instantly share code, notes, and snippets.

@timjstewart
Created April 12, 2020 20:51
Show Gist options
  • Save timjstewart/f54e0dfba2435d81bc3836c7e60b90f3 to your computer and use it in GitHub Desktop.
Save timjstewart/f54e0dfba2435d81bc3836c7e60b90f3 to your computer and use it in GitHub Desktop.
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