0

Capital A in Vim takes me to the last character in insert mode, but can I go to the nth-to-last character in insert mode (or append mode) in vim?

Example:

this is some t|ext

how to go specifically to the location of the | in insert mode, I would imagine something like <n>+A where n is an integer. I did see a similar question here: how-to-go-to-before-last-character-in-a-line and an answer suggested to use $i, to go to the second-to-last character in insert mode, but this can't go to the nth character.

[Edit]:

I only want to end up in insert mode, not necessarily do all the commands in insert mode but rather do them in normal mode.

9
  • 2
    that's what normal mode is for ;) Sep 15 at 17:09
  • 2
    Welcome to Vi and Vim!
    – filbranden
    Sep 15 at 19:14
  • 2
    @an4s911 You can also use Ctrl+O from Insert mode to enter a single Normal mode command and stay in Insert mode otherwise. So, for example, you can use Ctrl+O 20 | to go to column 20 in the current line (and continue in Insert mode) or Ctrl+O gM to go to the middle of the current line. Unfortunately there isn't a single Normal mode command to go to the nth-character before the end of the line, so Ctrl+O isn't that helpful then, but if you create a Normal-mode mapping to take the count and go to the nth character before the end, Ctrl+O can help you access it.
    – filbranden
    Sep 15 at 19:19
  • 2
    @filbranden @Christian as I understand it, OP does not ask to move while in insert mode, but to enter it afterwards as would A do.
    – Biggybi
    Sep 16 at 17:48
  • 1
    @an4s911 Yes gM takes you to the middle of the line, see :help gM.
    – filbranden
    Sep 16 at 20:00
0

<ALT-$> [count] hi where [count] is a number

  1. the Alt key to enter commands while in insert mode
  2. while pressing the Alt key press "$" to go to end of line
  3. press [count] "h" to go left [count] times
  4. press i to go into insert mode
3
  • 1
    Welcome to Vi and Vim! I'm not sure your answer is actually addressing the question. One part of the question is about moving while in Insert mode, while your answer seems to include Normal mode commands only... Your answer was also flagged due to being too short, make sure you further explain what the commands are doing, why they're needed, etc.
    – filbranden
    Sep 15 at 19:14
  • 1
    @fibrandon edited
    – Drek
    Sep 15 at 19:48
  • 1
    @filbranden by ‘in insert mode’ I actually meant doing the commands in normal mode and then finally ending up in insert.
    – an4s911
    Sep 16 at 18:56

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.