Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Delete from cursor to next period

Tags:

vim

Is there a shortcut in vim to delete from the current cursor to the end of the sentence?

                                  cursor
                                    v
This is half a sentence.  My cursor is here, but I would
like to delete to this period.  I do not want to delete this part.
                             ^
                     delete from cursor to here

Imagine my cursor is somewhere on the text that says My cursor is here,. How can I delete from this line all the way (and including) that next .?

like image 992
Daniel Kaplan Avatar asked Dec 19 '22 05:12

Daniel Kaplan


1 Answers

Though there's no exact motion for that, there are several possibilities:

  1. The ) motion deletes the remainder of the sentence, but that also includes the whitespace after the period.
  2. If there were no hard line break, you could use the useful f motion (which only works in the current line, unless you install a plugin): f. This is also useful if you want to keep the period: t.
  3. The most general motion is search via /. You need to search for a literal period (\.), and to include it, move to the end (/e) of it: /\./e<Enter>.

All of these have to be appended to the d "delete" command, which takes a {motion}.

Learn how to look up commands and navigate the built-in :help (here, :help motion.txt in particular); it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.

like image 105
Ingo Karkat Avatar answered Jan 14 '23 20:01

Ingo Karkat