3

This question already has an answer here:

In Emacs, C-o or M-x open-line creates a blank new line under the point/cursor without moving it.

Since c-l isn't used in insert mode and I like I have the following two lines in my .vimrc.

" C-o from emacs (open line at current point)
inoremap <c-o> <esc><esc>mpA<cr><esc><esc>`pa
" make C-l do C-o's job
inoremap <c-l> <c-o>

This mapping has a number of drawbacks

  • It clobbers whatever is in the p register
  • If I use the c-o binding when my cursor is at the beginning of the line, after executing c-o my cursor is at position 1 instead of position 0.
  • I have set so=7 so that I always see seven lines around my cursor if possible. If I'm near the bottom of this window invoking c-o counts as cursor movement

Is there a way of adding a new line below the cursor without changing its position or using a register?

marked as duplicate by Peter Rincker, nobe4, statox, EvergreenTree, vappolinario Jul 6 '16 at 21:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    are you looking for :inoremap <silent> <c-o> <c-o>:call append('.',"")<cr>? Note: I woudln't recommend mapping <c-o> away. – Christian Brabandt Jul 3 '16 at 20:18
  • @ChristianBrabandt yes that's perfect! I decided to map that command to <c-l> instead based on your warning. – Gregory Nisbet Jul 3 '16 at 20:21
  • 1
    The unimpaired plugin might be of your interest, where [<space> and ]<space> put a blank line before/after the cursorline. – Al.G. Jul 4 '16 at 12:51
1

You could also try a vimscript function

function NewLine()
    let l:position = getcurpos()
    normal o
    call cursor(l:position[1], l:position[2])
endfunction

you can then map it to with

inoremap <silent> <c-l> <c-o>:call NewLine()<cr>

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