ruggedbuteducated
ruggedbuteducated

Reputation: 1348

Deleting lines upward in vim Linux

How to do that in vim, lets say im in line 100 and i want to delete 20 lines upward? how to do that in vim linux?

Upvotes: 3

Views: 420

Answers (3)

Stefan
Stefan

Reputation: 114138

You can do it relative if you know the number of lines:

d20k

Or absolute if you know the line number:

d80G

d = delete, 20k = 20 lines up, 80G = goto line 80

Or without taking you current position into account:

:80,100d

Personally, I use visual mode a lot becuase it gives me a nice feedback:

  • hit V to enter visual line mode
  • move 20 lines up with 20k
  • adjust selection with k and j if necessary
  • press d to delete selection

Upvotes: 7

jbr
jbr

Reputation: 6258

In normal mode you can use d and the movenment key k to delete upwards. And then you prefix that command with the number of times you want to repeat the command like 100dk.

If you just want to delete to the beginning you can use gg along with d, gg sends the cursor to the first character in the file. So ggd will delete the first line to the line you are standing on.

Upvotes: 5

thar45
thar45

Reputation: 3560

You can do it upwards with the range.

:-20,.d

In this you can specify the range of line to delete it .

Will deletes 20 lines upwards to the current and this is kind of an ex-mode command.

Upvotes: 3

Related Questions