Favorite Vim Tricks

These are some of my favorite or most easily forgotten vim tricks

Of course, there is a fantastic educational newsletter, VimTricks. You should subscribe and get all the tricks they have. These are some I've learned from them and elsewhere that I want to remember and highlight for myself.

Copy lines by line number

  • :281t. – Copy line 281 and paste it below the current line

  • :-10t. – Copy the line 10 lines above the current line and paste it below the current line

  • :+8t. – Copy the line 8 lines after the current line and paste it below

  • :10,20t. – Copy lines 10 to 20 and paste them below

  • :t20 – Copy the current line and paste it below line 20

From VimTricks

Close all other buffers

:%bd|e#

  • %b - all buff

  • d - delete

  • | - pipe?

  • e# - open the last buffer for edit

Delete duplicate lines

Visual line select something, then:

:sort u

  • u - unique