Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period?

The commands df., d), and D all truncate the sentence but don't keep the period. Manually, I can type d/\.<ENTER>:noh<ENTER>.

For example: I have this sentence and the cursor is at the position marked by the caret:

Scholar X's monograph is a groundbreaking study but I don't like it.
                                               ^

I want to type one command (say, Ds) and get this:

Scholar X's monograph is a groundbreaking study.
share|improve this question

t and f are nice when we are on the same line. If the period is on another line, we're back to /\.. If you want to type ds, or cs, or ys, ... it can be done thanks to an operator-pending mode mapping:

:onoremap s /\./<cr>
" and for visual mode, with e-1 to exclude the period.
:vnoremap s /\./e-1<cr>

But honestly, I'll bind this to . instead of s as s already does something in visual mode.

share|improve this answer

You had the right idea with df.. Of course, f goes up to the period like you noticed. If you use t (mnemonic until) instead, it will go forward until the period, but not to it. From :h t

                            *t*
t{char}         Till before [count]'th occurrence of {char} to the
            right.  The cursor is placed on the character left of
            {char} |inclusive|.
            {char} can be entered like with the |f| command.

So if your buffer is like this:

Scholar X's monograph is a groundbreaking study but I don't like it.
                                               ^

and you type t., you will be here:

Scholar X's monograph is a groundbreaking study but I don't like it.
                                                                  ^

The f and t commands mirror eachother very nicely. In fact they're pretty much identical other than f moving one further.

  • They can both be repeated with ; and ,

  • They both have uppercase variants that move backwards instead of forwards

share|improve this answer
    
I accepted this before realizing it doesn't work if the sentence ends on another line. Is that possible with these commands? – musarithmia 12 hours ago
    
I personally think of the mnemonic for t as up to – Paul Evans 2 hours ago

With no extra configuration involved, I would just use:

c).<Esc>

Bonus: It's repeatable with the dot command.

Also bonus: It works on any POSIX vi and is not Vim-specific.

And actually, I would use <C-[> (or "Ctrl+[" if you speak Windows) rather than actually pressing the "Escape" key.

share|improve this answer

In your case I would do the following:

ma)bd`a
^^^^^^^
||||||+ mark a
|||||+  line position
||||+   delete
|||+    go to end of last word
||+     start of next sentence
|+      mark a
+       set a mark

Although not one command as you ask, this does if you're used to using marks roll off the fingers with reasonable ease.

share|improve this answer

After reviewing the other answers I thought of this:

map ds v)2hx

Enter visual mode, go to the end of the sentence (even if on subsequent line), back up two characters to exclude the period, and delete.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.