AnswerBun.com

How to select/delete until end of file in vim/gvim?

Unix & Linux Asked on January 3, 2022

Accidentally I managed to copy-paste a paragraph in vim a zillion times.
How do I select and then delete the text from my current position to the end of file?

In Windows, this would be Ctrl-Shift-End, followed by Delete.

6 Answers

Vggx didn't work for me, but vG$d did. vG$ selects to EOF (last character of last line), then whatever command you want to executed.

=This approach (command after selection) seems to work better. Of course, I'm using Vim 8.1 on Windows 10, and a few years later.

Answered by user3473636 on January 3, 2022

vGx

works fine for multi line selection(in this case paragraph), but if you want to select within one single line it acts mysteriously(selects from cursor till beginning of the line).

In case of selection within Single line you have to use:

v$x

Which enters to Visual mode("v") and goes to end of line("$") and deletes("x") from current position until end of line.

Answered by Kayvan Tehrani on January 3, 2022

Yet another method: :.,$d

That means in ex mode, address current line to end, and delete.

Answered by Keith on January 3, 2022

You could also just type u to undo the changes that resulted in the errant copy-paste.

Answered by vimmar on January 3, 2022

d is delete and G moves to the end of the file, so dG will delete to the end of the file. It includes the entire current line though; if you're mid-line and want to preserve everything before the current position you need to use Mark's method

Answered by Michael Mrozek on January 3, 2022

VGx

Enter Visual Mode, go to End of File, delete.

Alternatively, you can do:

Vggx

To delete from the current position to the beginning of the file.

Answered by Mark Szymanski on January 3, 2022

Add your own answers!

Related Questions

Lenovo Ideapad 330 – most of bootups end with black screen

1  Asked on December 31, 2021 by freddie-chopin

     

SCP from remote CentOS to Ubunto host

0  Asked on December 31, 2021 by phil-rushton

       

What is the easiest way to setup LUKS on a new image?

0  Asked on December 31, 2021 by eng3

 

HDMI input not detected on Debian 10

0  Asked on December 31, 2021 by judeb

       

How to match multiple columns between two files?

1  Asked on December 31, 2021 by hambone

     

/tmp full but… empty

1  Asked on December 31, 2021 by clment-moissard

       

Disable Ethernet Hardware Devices at start-up

1  Asked on December 29, 2021 by nickaz

         

Multicast frames in Linux bridge dropped

2  Asked on December 29, 2021 by tanvir-k

     

Disable Internet Access on Eth0

3  Asked on December 29, 2021 by swapfile

     

F2FS feature-list

2  Asked on December 29, 2021 by user252842

   

Dual Boot Help (Win10 and CentOS8)

3  Asked on December 29, 2021 by diode121

       

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP