Skip to main content
Vim Text Editor:

Vim: Delete from current position to end of line

Summary

Learn how to efficiently delete text from the current position of the cursor to the end of the line in Vim using simple commands like the D command, the d$ command, or using x for forward deletion character by character.

Introduction #

One of the fundamental editing actions in Vim is deleting text, and knowing how to quickly delete from the current cursor position to the end of the line can significantly enhance your workflow.

Before using deletion commands, ensure you are in normal mode.
Press Esc to switch to normal mode if you are in insert or visual mode.

Using the D command #

The quickest way to delete from the current cursor position to the end of the line in Vim is by using the D command:

  • Press D in normal mode, and everything from the cursor position to the end of the line will be deleted.
  • This command is equivalent to d$, which also performs the same action.

Using the d$ command #

Another way to achieve the same result is using the d$ command:

  • d stands for “delete.”
  • $ moves the cursor to the end of the line.
  • Together, d$ deletes everything from the cursor to the end of the line.

Using x for forward deletion #

If you want to delete a single character forward from the cursor position, you can use the x command:

  • Press x in normal mode to delete the character under the cursor.
  • Repeating x will delete subsequent characters one by one.

Mastering the D or d$ command in Vim can help you navigate and edit text more efficiently. Additionally, using x allows for quick character deletion. Whether you’re working with code, configuration files, or general text, these simple tricks will streamline your workflow and make you a more effective Vim user.

Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

Vim: Delete from current position to end of line by Jonas Jared Jacek is licensed under CC BY-NC-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. If others modify or adapt the material, they must license the modified material under identical terms. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/delete-from-current-position-to-end-of-line-in-vim">Vim: Delete from current position to end of line</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-NC-SA 4.0</a>.</p>

For more information see the Ditig legal page.

All Topics

Random Quote

“Content precedes design. Design in the absence of content is not design, it's decoration.”

 Jeffery Zeldman American web designer, author, and advocate for web standardsTwitter, - IT quotes