6

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.

2 Answers 2

12

If the . character is on the same line as the cursor, you can do dt., or ct. to enter insert mode after the deletion.

1
  • Wow, that's excellent. Exactly what I was looking for, actually; it neatly sidesteps the entire problem I was having. I'm going to have to spend some time reading the motions in the Vim docs.
    – Reid
    Jun 5, 2011 at 17:15
6

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.

3
  • The first doesn't work for a case like $('div').remove() (to use a contrived example) where I want to remove $('div') to place it in a variable. But your ^M trick does work; I didn't even think of that. The final result is map <leader>. d/\.^M:noh<cr>. Thanks. :)
    – Reid
    Jun 5, 2011 at 16:50
  • Also, I thought the only way to delimit the search for \. from :noh was to use :normal so that I could use <cr>. But with ^M, this isn't necessary. (Without the ^M, it was searching for \.:noh instead.)
    – Reid
    Jun 5, 2011 at 16:52
  • Anyone curious why the ^M is needed when searching with normal can read this answer. Mar 11, 2014 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .