11

I've been using vim for a few years as a secondary editor but for various reasons, I find myself using it more and more even when my primary editor is available. One problem that has always bugged me about vim, and that keeps me from using it more, is the way it handles cursor placement. The cursor can only be on a character, rather than between characters, as would be the case with any editor created since 1984.

For just one example of why this is a problem, if I want to delete the last word on a line, I hit $ to go to the end of the line, and then db to delete backward. This leaves a character to delete, because $ didn't really go to the end of the line, it went to the last character of the line, and db deleted only what was before the current character. The problem isn't that I have to type an extra character, it's the extra thought involved in doing what ought to be simple, which distracts my attention away from what I'm actually trying to accomplish.

It seems to me that the more modern idea cursor placement is in every way superior, and I'd like to switch vim to use that approach. I'm sure some hard-core vim fans will disagree with my view on that, but since one of the standard arguments for vim's superiority is its infinite configurability:

  • can it deliver in this case?
  • Can vim be made to place the cursor between characters?
17
  • 2
    Sounds like you are looking for Insert mode or missing the point of normal mode. I'd do $daw or $bdw to delete the last word on a line in normal mode. In Insert mode I would do A<Ctrl-w>.
    – jw013
    Commented Aug 15, 2012 at 16:50
  • 3
    For the record, as someone who's frightened by the very idea of a netherworld "between characters", the correct key sequence to delete the last word on the current line is $bD
    – Alan Curry
    Commented Aug 15, 2012 at 17:28
  • 1
    Using a mouse is not ideal, but the significant inefficiencies come when you have to stop and think about how to do what you want to do. The real thing that is precious is not a second here and there, but focus. When you lose focus you lose far more than a few seconds.
    – iconoclast
    Commented Aug 15, 2012 at 20:26
  • 2
    From the comments so far it sounds like the answer to the question is "No, this model of cursor movement is irrevocably embedded in vim's design and cannot be changed." Is that correct?
    – iconoclast
    Commented Aug 15, 2012 at 20:45
  • 2
    @iconoclast That's my conclusion too. As far as I can tell, it is impossible in vi or vim to treat all characters on a line uniformly, there is always an exception for the first or last character. Commented Aug 15, 2012 at 22:36

1 Answer 1

5

You can :set virtualedit+=onemore, which allows you to go just past the last character. Unfortunately for you, $ still goes to the last character; you have to cursor over to get past it. On the other hand, you can use g$, which normally goes to the last character of the screen line on a line that wraps; in onemore mode it also goes just past the last character of a non-wrapped line (or the last screen line of a wrapped line).

:h 'virtualedit' says this option can mess up scripts, but I don't know how big a risk that is in reality.

0

You must log in to answer this question.

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