7

I've recently been editing some source code where I often want to swap elements in an array that spans multiple lines.

Doing this manually is quite tedious, moving the cursor between both locations and copy-pasting twice.

It's possible to write a utility that does this - which would be much faster than copy-pasting between two locations (either with a single mouse drag, or marking two locations with the cursor).

However for all I know this may already exist.

Does Emacs provide a convenient way to do this, or is there a package this supports this feature?

1
11

Function transpose-words can do that.

  • Set a mark at one word (C-SPC).
  • Move the cursor to the other word.
  • C-0 M-t

Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.