Duplicate a whole line in Vim
如何在Vim中以类似于在Eclipse中的IntelliJ IDEA / Resharper或Ctrl + Alt +↑/↓中的Ctrl + D的方式复制整行?
yy or Y to copy the line
or
dd to delete (cutting) the line
then
p to paste the copied or deleted text after the current line
or
P to paste the copied or deleted text before the current line
Normal mode: see other answers.
The Ex way:
: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*classs+i+/t. will copy all subsequent lines of the form class xxx right after the cursor. Reference: :help range , :help :t , :help :g , :help :m and :help :v
YP或Yp或yyp 。
上一篇: 如何在Vim中移动到行尾?
下一篇: 在Vim中重复整行
