DEV Community

Discussion on: How to flip array keys and values in the code editor?

Collapse
 
voyeg3r profile image
Sérgio Araújo • Edited

As a test I have tried on vim

/\v^('\w+')( .. )('\d+'),
:%s//\3\2\1,
Enter fullscreen mode Exit fullscreen mode

OBS: I have used the caret as if the pattern started at the begining of line but we can also cosider the space optional

/\v^(\s+)?('\w+')( .. )('\d+'),
:%s//\1\4\3\2
Enter fullscreen mode Exit fullscreen mode

Another tip: Using neovim we have the "inccommand" that allow us to match our regex icrementally. Then we can refer to our search simply by using //