sponsor Vim development Vim logo Vim Book Ad

basic Tip #47: Swapping characters, words and lines

 tip karma   Rating 11/13, Viewed by 1298 

created:   March 13, 2001 13:08      complexity:   basic
author:   Anonymous      as of Vim:   5.7

To swap two characters or lines, use the following commands:

xp       -     delete the character under the cursor and put it afterwards.
               (In other words, it swaps the characters.)

ddp      -     delete the current line and put it afterwards.
               (In other words, it swaps the lines.)

Unfortunately there is no universal solution to swap two words.
You may try the following ones, but don't expect too much of them:

dawwP    -     delete the word under the cursor, move forward one word
               and put it back after the cursor.  (In other words, it
               swaps the current and following word.)
              
dawbP    -     delete the word under the cursor, move backward on word
               and put it back after the cursor.  (In other words, it
               swaps the current and preceeding word.)

 rate this tip  Life Changing Helpful Unfulfilling 

<<Win32 binaries with perl, python, and tcl | Moving around >>

Additional Notes

Anonymous, August 27, 2001 4:54
I prefer to use dawelp.
[email protected], October 15, 2002 12:12
The tip http://vim.sourceforge.net/tips/tip.php?tip_id=329 shows how
to swap a pair of adjacent words, potentially separated by punctuation.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo