How to delete, including the current character?

99封情书 提交于 2019-12-21 07:05:13

问题


Let's say I've typed "abcdefg", with the cursor at the end. I want to delete back to the c, so that I only have "abc" left.

Is there a command like d that includes the current character? I know I could do dTcx, but the x feels like a work-around and I suppose there's a better solution.


回答1:


No. Backward motions always start on the left of the current character for c, y and d which is somehow logical but also unnerving.

The only "clean" solutions I could think of either imply moving to the char after c first and then do a forward delete:

Tcde

or using visual mode:

vTcd
v3hd

But, given your sample and assuming you are entering normal mode just for that correction, the whole thing sounds extremely wasteful to me.

What about staying in insert mode and simply doing ?




回答2:


try this:

TcD

this will leave abc for your example... well if the abcdefg is the last word of the line.

if it is not the last word in that line, you may do:

ldTc

or golfing, do it within 3 key-stroke:

3Xx or l4X



回答3:


See this answer to a similar question : there is a setting to be allowed to go beyond the end of the line

From the doc :

Virtual editing means that the cursor can be positioned where there is no actual character. This can be halfway into a tab or beyond the end of the line. Useful for selecting a rectangle in Visual mode and editing a table. "onemore" is not the same, it will only allow moving the cursor just after the last character of the line. This makes some commands more consistent. Previously the cursor was always past the end of the line if the line was empty. But it is far from Vi compatible. It may also break some plugins or Vim scripts. For example because |l| can move the cursor after the last character. Use with care! Using the $ command will move to the last character in the line, not past it. This may actually move the cursor to the left! The g$ command will move to the end of the screen line. It doesn't make sense to combine "all" with "onemore", but you will not get a warning for it.

In short, you could try :set virtualedit=onemore, and see if your environment is stable or not with it.




回答4:


Use d?c That will start d mode, search back to 'c' and then delete up to your cursor position.

Edit: nope, that does not include current position...




回答5:


I may be misunderstanding your request, but does 3hd$ do it?



来源:https://stackoverflow.com/questions/15804179/how-to-delete-including-the-current-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!