1

I'm having trouble understanding the cursor in the context of Vim commands, e.g. insertion, deletion, movement, etc:

  • When the cursor is hovering over a character and I want to delete until the end of the line, or to the beginning of the line, should I expect that the character it's pointing to will also be deleted?
  • When I enter insert mode, should I expect that the insertion will take place before or after the current character?
  • What about when pasting with p?

I'm not looking for specific answers to these examples, I'm looking for a general explanation or rules to understand the "current position" so I don't keep executing commands that end up being off by 1 character because I misinterpreted it. In GUI editors the caret usually sits between instead of on top of characters, so it's never been a source of confusion.

  • 1
    You said you don't want specific answer but that's what you should be looking for: Deleting until the end of the line see :h D and you'll read Delete the characters under the cursor until the end of the line, entering insert mode if you use a you append text after the cursor if you use i you insert text before the cursor, if you read :h p and scroll to :h P you'll see that one command is 'paste before' and the other 'paste after'... Your best option is to read the doc – statox Dec 13 '16 at 9:01
  • 1
    Note that Vim allows you to configure the shape of the cursor fairly extensively (see :help guicursor). I wouldn't recommend that you change it to be a vertical-bar type cursor when in normal mode (It might help you interpret motions, but I think it would make commands like a and p confusing), but you can. – Rich Dec 13 '16 at 10:24
  • @statox sure, but I assumed there was a general principle / rhyme / reason to why the commands worked the way they did, and that it would be consistent across these commands and commands I haven't yet encountered where I can anticipate behavior. Ingo Karkat's answer shed some light in this respect. – Kvass Dec 13 '16 at 19:31
3

The right mental model is that the cursor is before the current character. So, any {motion} that moves to the right (e.g. $, w) includes the character under the cursor, whereas any motion to the left (e.g. ^) excludes it.

Likewise, i inserts before the current character, whereas a appends after it. Same for pasting with P (before) / p (after).

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.