4

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 '16 at 6:10
  • Just in case you were wondering: <C-O>a. – Antony Jul 17 '16 at 21:15
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.

1

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, privacy policy and cookie policy

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