According to http://vimdoc.sourceforge.net/htmldoc/usr_41.html#function-list vim script has functions setline() and append() to modify the current buffer but how do i delete a line from within a script? With setline(1, "") the line is only emptied but I want to get rid of it.
3 Answers
You use the ex command :d. :5d
deletes line 5.
-
3I'm still a bit puzzled why there is no API function for doing something so important but apart from that 'exe ":1," . lastline . "d"' does everything I want (actually I wanted to delete a whole range of lines).– aheMar 28, 2010 at 22:14
-
2Because there's no need for a function to do that. You have a command that can do it. Vimscript is a base of all the ex commands normally available plus additional functions to provide functionality that isn't available (or easily available) through the ex commands.– jamessanMar 29, 2010 at 11:56
-
4It would be nice to be able to delete a line without affecting the undo list, though. Sep 10, 2012 at 20:33
One addition: don’t do execute line 'delete'
, do execute line 'delete _'
: deleting to black hole register has a minimal number of side-effects. Without _
it will delete to default register, numbered register 1
and will move all other numbered registers (except 0
which is for yanks): 1
->2
, 2
->3
, …, 9
->void.