Is there any command in Vim that will do the same thing as o
or O
(insert a blank line before/after the current one), but which doesn't also switch into insert mode?
Press Enter to insert a blank line below current, Shift + Enter to insert it above.
To answer the question as asked, you'd have to do sed 's/pattern. */&\n/' , otherwise you'll insert the newline right after the match instead of at the end of the line.
By default, Vim starts in “normal” mode. Normal mode can be accessed from other modes by pressing Esc or <C-[> .
vi new line commandsThe lowercase letter "o" lets you open a new line just below your current line. When you use this command, vi creates a new blank line below your current line, and puts you in insert mode at that position. The uppercase letter "o" lets you open a new line just above your current line.
:nnoremap <silent> [<space> :pu! _<cr>:']+1<cr> :nnoremap <silent> ]<space> :pu _<cr>:'[-1<cr>
Explanation:
:put
will paste a register linewise below. (:pu!
above):pu _
will paste the blackhole register, which is empty so we get a blank line'[
and ']
marks are set at the start and end of a changed or yanked text.:'[
will move the cursor to the starting line of the last change (the put in this case):'[-1
will move the '[
but up one more lineIf you prefer a plugin then I suggest Tim Pope's unimpaired.vim. Which supplies these mappings, but will also take a count. The plugin also has many other nice mappings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With