2

Let's say I have this line in Vim and I click $ to reach EOL.

Hello Worl*d

The asterisk marks the place of the cursor, i.e. enter image description here

Let's say now that I wanted to delete backwards until the space, so I use dT<Space>. This leaves me with:

Hello *d

The problem is that the cursor is actually between the l and the d.

Another option in this case would diw (or diW if the word contained hyphens etc), but I like to be able to use the motion that first pops up in my head, and sometimes it's more obvious to do a motion until a character.

Is there any workaround here? One idea is to have the cursor moved to the right of the cursor block, instead of the left. I haven't found anything on this.

  • Where do you see a /? – harrymc Jan 30 '19 at 11:23
  • Not slash, I cursivated the l and d in World. I fix it so we avoid misunderstandings. – Max Jan 30 '19 at 12:29
1

I understand that the problem is to delete the last word in the line when the EOL character immediately follows this word, when your preferred shortcut leaves the last character without deleting it.

The problem might be because Vim makes a distinction between inclusive and exclusive motions. Using v toggles the "inclusiveness" or "exclusiveness" of a motion.

So you may use this combination: d+v+T+Space

See :help inclusive for an explication.

If this is too long, you may record a macro for it.

You could also use the following shortcuts:

daw : delete the word under the cursor (includes spaces before the next word)
caw : same and puts you in insert mode 
diw : delete entire word without touching whitespace around it
daW : delete all characters between two whitespaces
| improve this answer | |
  • Just what I was looking for. Will use the v command a lot, for sure. Thanks for the options as well. – Max Jan 30 '19 at 14:28
1
  • With :set virtualedit=onemore, you can move the cursor to the right of the last character, and your command would work: $ldT<Space>
  • As you've mentioned, the natural motion would be iw in this case.
  • Instead of T<Space>, you could also use b here.
  • I probably would use bD here.
  • If dT<Space> is what first comes to your mind, you can correct the missed character with x. As long as you don't use the deleted contents or undo, this doesn't matter.
| improve this answer | |
  • Thanks for the clarification and the possible solutions, I read up some one "onemore" and it seems that it may break some plugins etc, so I'll opt for the solution to toggle vinclusiveness. – Max Jan 30 '19 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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