Search code examples
vimabbreviation

Vim abbreviations - end in insert mode


Been through several guides to set up some simple Vim abbreviations. I'm almost there, I just can't seem to find how to end IN insert mode.

What I have:

iab cl console.log()<Esc>F%s<c-o>:call getchar()<CR><Left><Left>

What happens:

cl expands to console.log() and the cursor is placed over )

What I want to happen:

Same thing except I want to enter insert mode.

What I've tried:

After <Left> I've tried:  <Insert>, i, and <Ins> with no luck.

Solution

  • The problem is that the abbreviation is encountering an error and stops executing.

    This part <Esc>F%s<c-o>:call getchar()<CR> doesn't make sense to me and looks like it would be causing the error. Multiple parts of it could be the problem. But most likely the F% because it can't find a percent sign going backwards.

    I think the fixed mapping should be something along the lines of this (however I don't think this does what you want) It does end in insert mode since the abbreviation completed successfully and the abbreviation doesn't do anything to exit insert mode.

    iab cl console.log()<Left>
    

    Take a look at this to https://stackoverflow.com/a/11865489/1890567 remove the trailing whitespace. from the abbreviation.