Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm putting text in a particular area in vim... enter image description here

I'm using REPLACE mode so that I don't mess up the 'far edge' of the 'rectangle' when I type. It would be great if when I pressed enter in this mode my cursor ended up on the next line without affecting the rest of the line.

But unfortunately when I press enter a new line is inserted and I end up with

enter image description here

which messes up the 'rectangle' - does anyone have any ideas about how to get the behaviour I'm looking for?

share|improve this question
Your carriage returns are invisible, but they're still carriage returns, which are designed to move the cursor to the start of the next line. What you're looking for is the "down arrow" key. – Lèse majesté Mar 11 '12 at 12:11
Quite right - I've edited the title to make that more clear. Thank you for your tip about the down arrow - but on my example, the down arrow just moves the cursor down, it doesn't move it 'down and to the start of the next line', which is really what I'm looking for - I hope this clarifies things... – Joe Mar 11 '12 at 12:16
I suspected that might be what you wanted, but it seems like an unlikely feature. However, there are lots of extensions and hacks for Vim, so maybe someone else has found a way to do it. – Lèse majesté Mar 11 '12 at 12:20
up vote 3 down vote accepted

After tinkering, I came up with the following. It is a bit of a kluge, but it seems to work:

augroup ReplaceReturn
    autocmd InsertEnter * if v:insertmode ==? 'r' | call s:RedefineReturn() | endif
augroup END

function! s:RedefineReturn()
    inoremap <cr> <down><c-o>0
    inoremap <silent> <esc> <esc>:call <SID>UndefineReturn()<CR>

function! s:UndefineReturn()
    if maparg('<cr>', 'i') != ''
        iunmap <cr>
        iunmap <esc>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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