Skip to content

Instantly share code, notes, and snippets.

@Johnytran
Created March 9, 2016 09:07
Show Gist options
  • Save Johnytran/675f3016e049612ab80e to your computer and use it in GitHub Desktop.
Save Johnytran/675f3016e049612ab80e to your computer and use it in GitHub Desktop.
duplicate line in vim
:t. will duplicate the line,
:t 7 will copy it after line 7,
:,+t0 will copy current and next line at the beginning of the file (,+ is a synonym for the range .,.+1),
:1,t$ will copy lines from beginning till cursor position to the end (1, is a synonym for the range 1,.).
If you need to move instead of copying, use :m instead of :t.
This can be really powerful if you combine it with :g or :v:
:v/foo/m$ will move all lines not matching the pattern “foo” to the end of the file.
:+,$g/^\s*class\s\+\i\+/t. will copy all subsequent lines of the form class xxx right after the cursor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment