Delete a block of text in Vim
So I can delete a text+line using dd (normal mode) and all the below text moves up a line.
I can go into visual mode using Ctrl+v
If I then say do 0
> C+v
> jjj
> $
> d
the text of 4 rows is deleted but the lines are not deleted.
How do I delete a block of text and delete the lines at the same time so any preceding lines of text move up to the cursor?
For something like this I usually use shift+v, jjj...d, but you could delete using text objects as well.
See :h text-object
. A few examples:
di"
- delete inside "
dap
- delete around paragraph
And you could of course use other commands than d
, such as c
or v
.
Something I use all the time is ci(
and ci"
for editing content inside ()
and ""
.
More cool examples using text-objects and visual mode can be found here:
What is your most productive shortcut with Vim?
You could use as well, ie 4dd
as mentioned by FDinoff, or a range, mentioned by Jens. However in most scenarios I personally believe using visual line (shift+v) is more flexible, and you don't have to count lines or anything. It's easy to remember, you see the result instantly, you won't miss counting lines and it'll work even if you're at the top/bottom on the screen.
Use either 4dd
to delete 4 lines of text.
Or
Use linewise visual block. <Sv>
then move to the last line you want to delete then press d
If the block is really large, and you can't be bothered to count the number of lines to delete, but you know the first and last line numbers ( :set number
helps), you can always go to ex mode and
:3,1415d
to delete from line 3 through line 1415.
链接地址: http://www.djcxy.com/p/49500.html上一篇: 将光标后的文本移动到新行
下一篇: 在Vim中删除一段文本