Vim Tips Wiki
Vim Tips Wiki
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Tip 1506 Printable Monobook Previous Next

created 2007 · complexity basic · author Mike Brotherston · version 7.0


Suppose you have a statement (C/C++/Java/etc):

alpha = beta;

and you want to change it to:

beta = alpha;

Try this mapping:

noremap <C-S> :s/\([^ =]*\)\([ ]*\)=[ ]*\([^;]*\);/\3 = \1;/<CR>:nohl<CR>

<C-S> may cause Unix terminals to suspend. Replace with <F2> or something easy to remember for your own purposes.

This mucks with your current matched highlighting selections; thus the trailing :nohl. If someone knows how to do this without mucking with the incremental searches jot it down.

Comments

Advertisement