Last Updated: February 25, 2016
·
557
· gagallo7

ViM - Swap sides: LHS <-> RHS

Swap Left Hand Side with Right Hand Side in ViM!

Example:

Input:

a [ 2 + x ] -= b [index-stride*8];

Output:

b [index-stride*8] -= a [ 2 + x ] ;

ViM command:

:s/\([ ]*\)\([^=^\t]*\)\([+-/* ]=\) \([^;^\t]*\);/\1\4 \3 \2;

Remmaping to F2:

noremap <F2> :s/\([ ]*\)\([^=^\t]*\)\([+-/* ]=\) \([^;^\t]*\);/\1\4 \3 \2;<CR>:nohl<CR>