Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete till end of sentence in vim

Tags:

So I'm playing vim adventures and I got stuck. I need a Vim command that will delete the keys in red. I thought dd would do it, but that only deletes the current line.

enter image description here

like image 735
Aakil Fernandes Avatar asked May 28 '15 03:05

Aakil Fernandes


People also ask

How delete from the end of the Vim?

Deleting a Line Press the Esc key to go to normal mode. Place the cursor on the line you want to delete. Type dd and hit Enter to remove the line.

How do I delete an entire text in Vim?

Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it. If Vim is in another mode, for example, insert mode, you can access normal mode by pressing Esc or <C-[> .

How do you quickly delete in Vim?

Deleting a single line in Vim editor: To delete a line, follow the steps below: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.

How do you delete the remaining portion of the line from the cursor position?

As others have mentioned: you can use d$ or D ( shift - d ) to delete from the cursor position until the end of the line. What I typically find more useful is c$ or C ( shift - c ) because it will delete from the cursor position until the end of the line and put you in [INSERT] mode.


2 Answers

Use das or dis to delete a sentence. Use dap or dip to delete a paragraph. See :help text-objects for details. Unrelated to your question, see this wiki page for plugins that provide other, highly useful text objects.

like image 170
lcd047 Avatar answered Oct 23 '22 04:10

lcd047


) jumps to the beginning of next sentence, so d) will delete (from the cursor) till the beginning of the next sentence. Vim detects sentences using ., meaning period + space. This does mean that d) will have some problems if your cursor is on either the period or space delimiting two sentences, and will only delete until the first character of the next sentence (meaning it deletes either a space or the period and space, which is almost never what is desired). das will work as you probably expect, deleting the sentence and the delimiter (period + space).

If you specifically want to move (and delete to) the last character in a sentence it is more complicated according to this vi.SE answer:

like image 25
Alejandro Avatar answered Oct 23 '22 06:10

Alejandro