switch.vim
switch.vim copied to clipboard
Add ability to use global flag in switch mappings
In python I've found that sometimes I need to change dictionary to a list of key, value pairs. So from that
{'key1: 'value1', 'key2': 'value2'}
(('key1', 'value1), ('key2', 'value2'))
I don't think it's possible with current implementation because of lack of ability to use g modifier.
I'm sorry it took so long to get to this issue.
The problem with using the "global" modifier is that it's impossible to scope it to only a part of the line. If it were allowed, the substitution would be made on anything else in the line as well, not just in the limits of the dict.
I remember a while ago when I was investigating the issue I tried to come up with some clever implementation for it, but I found out it was much harder than I had thought. I left it around to think about it... which is why it took so long to communicate with you.
Unfortunately, at this time, I don't really have a good solution for you. If I were to implement this independently for something I need, I might use my sideways plugin, or at least its internal plumbing to locate the arguments: https://gist.github.com/AndrewRadev/bd15a43f8cc5f8ec3c01741cb88753bf. But, currently, I have no way to plug this into switch. I've been planning since the beginning to make it more configurable and allow not only substitutions, but the execution of general macros and functions upon a particular pattern, but I never got around to doing it.