* Anthony Fontanilla <[email protected]> [2010-02-12 11:18]:
> I know that to delete n lines, the command is dd[n],
> where n is the number of lines to delete.
>
> But what if I want to delete up to a certain line number?
> Say, if I'm on line 65 and I want to delete up to line 126
> without having to do the math, how could I do that?
in normal command mode:
d126G
explanation:
d deletion start
126G jump to line 126
mind you, this also works when the
jump to the line goes "backwards/up".
or on the command line:
:.,126d
explanation:
: switch to command line
. current line
, separator between line numbers
126 line 126
d delete
if the current line number is higher than
the second line then vim should prompt you:
Backwards range given, OK to swap (y/n)?
as usual, the "m,n" is a "line range"
which is used by the following command;
here, the command is 'd' (delete).
the last line in the buffer is denoted by '$',
so ".,$" means "from here to the last line",
and "1,$" means "from first to last line" -
which can be abbreviated with '%', so
":%d" deletes all lines in the buffer.
thank Bram for 'u' (undo)! :-)
you can also use search command with
"/.../" and "?...?" within line ranges.
so if you were editing an email with
its header as the first paragraph
then you can delete it like this:
:1,1/^$/d
and here's how to delete the signature starting
at the last sigdashes line to the very end:
:$?^-- $?,$d
and if typing this is too much then
map it all to some key combination. :-)
"kill header/signature":
:map ,kh :1,1/^$/d<cr>
:map ,ks :$?^-- $?,$d<cr>
deleting the current paragraph goes like this:
:map ,kp :?^$?+,/^$/-d<cr>
but this requires an empty line both before
and after the current paragraph, so it won't
work for the first and last paragraph if they
border with the first or last line, respectively.
using "dip" (delete inner paragraph)
for this is much easier, of course.
this uses text objects -
see ":help text-objects".
deleting all paragraphs which contain a given word
is as easy as applying "dip" from a global command:
:g/word/normal dip
there, i have answered more than was asked.
but simply i had fun doing so. enjoy vim! :-)
Sven
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php