Deleting up to a certain line in Vim

LinuxVimText Editor

Linux Problem Overview


I know that to delete n lines, the command is [n]dd, 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?

Linux Solutions


Solution 1 - Linux

d126G

Delete, line number, go.

A lot of commands in Vim can be followed by a move command to specify the scope.

Solution 2 - Linux

Use this command:
65,126d

Solution 3 - Linux

:.,126d

. is the actual line. If you want delete from the next line, you can use .+1 instead.

Solution 4 - Linux

:,126d

all done.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionneuromancerView Question on Stackoverflow
Solution 1 - LinuxBrian RasmussenView Answer on Stackoverflow
Solution 2 - Linuxsud03rView Answer on Stackoverflow
Solution 3 - LinuxZsolt BotykaiView Answer on Stackoverflow
Solution 4 - LinuxPeterView Answer on Stackoverflow