Vim Tips Wiki
Advertisement


Tip: Exchanging adjacent words

Created: Complexity: Author: Version:


Map a key combination to this regular expression: this transposes the keyword under the cursor with the next keyword, including skipping line breaks.

s/\v(<\k*%#\k*>)(\_.{-})(<\k+>)/\3\2\1/

To replace the keyword under the cursor with the previous keyword (no line breaks), use:

s/\v(<\k+>)(.{-})(<\k*%#\k*>)/\3\2\1/

I'm sure that a version to handle line breaks can be done. Especially if you relax the requirement of using \k.

Comments

Advertisement