TransWikia.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!

Ask a Question

Get help from others!

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