On bash's readline in emacs mode, I recently discovered the transpose functionality, giving me the opportunity to quickly fix a typo likedc dirto cd dirby pressing CTRL+T on the c character.Is there something similar in Vi/Vim that lets me swap characters and words around?
How do I flip characters or words like emacs' transpose?
normal mode
For characters, it's fairly simple: xp to swap the letter under the cursor with the following letter, and Xp to swap the letter under the cursor with the previous letter.The x command deletes the character under the cursor, leaving the cursor on the next character.  The X command deletes the character just before the cursor, leaving the cursor on the same character it was on.p puts (pastes) the last deleted or last yanked text just after the current cursor position.  (P puts it just before the current cursor position, so xP and XP both leave the text the way it was before you started.)For swapping words, I'm not sure; perhaps someone else can answer that.  You can come close with dawwP (or remap it to be shorter) but that will break on several edge cases, for example near the end of a line.