Opposite of J

August 13, 2011


In VIM you can use the command J to join to lines:

hello       -> J ->  hello goodday

Where the cursor is positioned somewhere on the ‘hello’ line.

But I often find myself wanting to use the opposite, I want ‘hello’ to be put after ‘goodday’. The cursor is now positioned on the ‘goodday’ line.

goodday    -> K -> goodday hello

The following mapping does that:

map     K       kddpkJ

In words:

  1. Go up 1 line: k
  2. Delete the entire line: dd
  3. Paste line below the current one: p
  4. Go up again: k
  5. Perform the join: J

In less words: switch the lines and then do a join.