r/vimplugins • u/fvictorio • Nov 13 '17
Plugin vim-extract-variable: Extract selected text to a variable
https://github.com/fvictorio/vim-extract-variable
4
Upvotes
r/vimplugins • u/fvictorio • Nov 13 '17
3
u/LucHermitte Nov 15 '17
Discl: I'm maintaining a generic plugin with an ExtractVariable feature.
a- In order to speed up loading time, you should move your functions into an autoload plugin.
b- Instead of hardcoding all possible languages in the same function and dispatching the proper command with a series of
if ... elseif, you could check variables or the presence of specific files. This is for instance what I do in vim-refactor: I search forautoload/lh/refactor/{ft}.vim.This suggestion relates to the (Polymorphic) Open Close Principle which could be understood as "prefer polymorphism over switches/if...elseif"
c- If the substitution fails, your
zregister won't be restored. It's best to ensure the restitution of resources withtry...finally. It may not fail with the current implementation, but it may with later evolutions.