Rahul Arora
Rahul Arora

Reputation: 55

How can I delete all lines from cursor position using vi

I have a file in Linux. I want to delete all lines from cursor position till the EOF. How can I do that using vi editor.

Upvotes: 2

Views: 6533

Answers (4)

grebulon
grebulon

Reputation: 7982

Do something like:

:1,$d

Replace 1 with the number of the line you're on.

: - gets you to command mode
1,$ - indicates a range from the first line to the end
d - the delete command

Upvotes: 3

Rahul Arora
Rahul Arora

Reputation: 55

Press Esc come to command mode

press v enter visual mode

Shift + g "selects everything from current position to EOF"

DEL "delete selected"

Upvotes: -1

Saransh
Saransh

Reputation: 687

Step 1: Esc -> to enter command mode

Step 2: press key d (d stands for delete, vim will wait for second input specifying number of lines to delete)

Step 3 : Shift + g (To delete till EOF)

Upvotes: 0

asio_guy
asio_guy

Reputation: 3767

Press **Esc** come to command mode

press **v** enter visual mode

**Shift + g** "selects everything from current position to EOF"

**DEL** "delete selected"

be careful it can even delete the first line in which case you probably need to do this from the next line in cursor.

Upvotes: 0

Related Questions