I have this map in my .vimrc:

inoremap <C-space> <C-o>l

So that, eg, if I'm in insert mode:

enter image description here

I can just type <C-space> to move out of parens:

enter image description here

It all works great in the middle of a line. But if that ) were the last character on the line, then the cursor won't move when I hit <C-space>. Which makes sense, because there is nowhere for it move to.

But what I want in this case is for <C-space> to behave as if I'd typed <esc>$a -- ie, gone to the end of the line in normal mode and pressed a to start appending characters.

How can I update my mapping to achieve this special behavior for the end of line case?

  • 1
    Why did you create that mapping when you already have right <right>?
    – romainl
    Mar 17, 2016 at 6:10
  • Just in case you were wondering: <C-O>a.
    – Antony
    Jul 17, 2016 at 21:15

2 Answers 2


Another option is to simply change your mapping to:

inoremap <C-space> <C-o><Space>

<Space> moves forward one character even when at end of line.

  • " insert mode: escape to normal mode, move 1 char and enter insert mode inoremap <c-l> <Esc>la " normal mode: skip a character and enter insert mode nnoremap <c-l> a I have used these mappings. I know Ctrl+right arrow does the job. But arrow keys are not so close to the home row. Please do suggest if you have any other key bindings. :)
    – rohith
    Jun 11, 2020 at 2:33

If I understand correctly what you want, you can simply set :set virtualedit=onemore and your mapping will start to work even at the line end case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.