How to cut an entire line in vim and paste it?
我知道如何在vim中使用v
命令,但我需要一些将删除整行的东西,它应该允许我在其他地方粘贴同一行。
按shift+v
将选择整行,按d
将删除它。
dd
in command mode (after pressing escape) will cut the line, p
in command mode will paste.
Update:
For a bonus, d
and then a movement will cut the equivalent of that movement, so dw
will cut a word, d<down-arrow>
will cut this line and the line below, d50w
will cut 50 words.
yy
is copy line, and works like dd
.
D
cuts from cursor to end of line.
If you've used v
(visual mode), you should try V
(visual line mode) and <ctrl>v
(visual block mode).
There are several ways to cut a line, all controlled by the d
key in normal mode. If you are using visual mode (the v
key) you can just hit the d
key once you have highlighted the region you want to cut. Move to the location you would like to paste and hit the p
key to paste.
It's also worth mentioning that you can copy/cut/paste from registers. Suppose you aren't sure when or where you want to paste the text. You could save the text to up to 24 registers identified by an alphabetical letter. Just prepend your command with '
(single quote) and the register letter (a thru z). For instance you could use the visual mode ( v
key) to select some text and then type 'ad
to cut the text and store it in register 'a'. Once you navigate to the location where you want to paste the text you would type 'ap
to paste the contents of register a.
上一篇: 更改.vimrc中的状态行颜色?
下一篇: 如何在vim中剪切整行并粘贴它?