Vim keybinding to delete up to (but not including) the next period

vim

I've noticed a common idiom in my editing is a desire to delete everything up to, but not including, the next period. After a bit of researching online, I found the following command will work (I didn't expect searches to work, but so they do):

d/\.

Then it highlights all periods on the page, so I want to follow this with :noh.

I tried making my own map:

map <leader>. :normal d/\.<cr>:noh<cr>

I chose to use :normal because I'm not sure how it would be able to "tell" where I wanted the search to end. However, this fails spectacularly. It does nothing. It shows in the statusbar that it does run :noh fine, so I assume it's getting through the command alright. It just doesn't work.

When I tried to run :normal d/\. as a command solely by itself (in Vim), I got the follow message in the statusbar:

YR:Aborting command d/

That's an error message from Yankring.vim, so I disabled it temporarily. Now once I run the command, it does nothing at all. Just happily sits there.

To clarify: typing the command manually works with or without yankring. It's just that I can't get any of the various maps I've tried to work, with or without yankring.

I believe the root of the issue is that when I type d/ normally, a prompt comes up for me to search (this method works fine). That's fine and everything, but is there any way to automate this action so it can be bound to <leader>.?

If any other information is needed, I'll gladly provide it.

Best Answer

Btw, if you want to delete a sentence you can use the sentence forward motion like this:

d)i.

Meaning, deleting the sentence including the period and then inserting it again.

d/\. is necessary, if you want to delete multiple lines and there is a non-text document context, e.g. empty lines in between text and you really want to delete to the next period.

If the period is on the same line, you can just use the till-before motion: dt.

Typing

:normal d/\.^M

(Ctrl+V + Enter at the end)

works for me.

But I have to say that I don't understand the need for :normal.

I mean, using

:map <F10> d/\.<CR>:noh<CR>

the search starts at the position where the cursor is located and ends at the next period.

Related Question