vim - How to delete a large block of text without counting the lines?
Solution 1:
Go to the starting line and type ma (mark "a"). Then go to the last line and enter d'a (delete to mark "a").
That will delete all lines from the current to the marked one (inclusive). It's also compatible with vi
as well as vim
, on the off chance that your environment is not blessed with the latter.
Solution 2:
I'm no vim guru, but what I use in this circumstance is "visual mode". In command mode, type V
(capital). Then move up/down to highlight the block you want deleted (all the usual movement commands work). Then remove it with x
or d
.
Solution 3:
You can use the visual mode also (some commands are usable with the delete option also)
vip vap to select paragraph, v2ap to select two paragraphs
dap works, d2ap also. You can delete within blocks of [
]
like da[
For reference: the types of objects. From vim documentation : section 4. http://vimdoc.sourceforge.net/htmldoc/visual.html
4. Operating on the Visual area *visual-operators*
...
The objects that can be used are:
aw a word (with white space)
iw inner word
aW a WORD (with white space)
iW inner WORD
as a sentence (with white space)
is inner sentence
ap a paragraph (with white space)
ip inner paragraph
ab a () block (with parenthesis)
ib inner () block
aB a {} block (with braces)
iB inner {} block
a< a <> block (with <>)
i< inner <> block
a[ a [] block (with [])
i[ inner [] block
Solution 4:
There are many better answers here, but for completeness I will mention the method I used to use before reading some of the great answers mentioned above.
Suppose you want to delete from lines 24-39. You can use the ex command
:24,39d
You can also yank lines using
:24,39y
And find and replace just over lines 24-39 using
:24,39s/find/replace/g
Solution 5:
It sort of depends on what that large block is. Maybe you just mean to delete a paragraph in which case a dip would do.