I want insert newlines in normal mode in vim using Shift-Enter and Ctrl-Enter. I try some solutions and mixing solutions from Vim Wikia - Insert newline without entering insert mode but Shift-Enter and Ctrl-Enter didn't respond:
" put a new line before or after to this line nnoremap <S-CR> m`o<Esc>`` nnoremap <C-CR> m`O<Esc>`` " reverse J command nnoremap <C-J> vaW<Esc>Bi<CR><Esc>k:s/\s\+$//<CR>$
Now if you want to add line break after a specific pattern, you can easily add line break '\r' after the cur pattern above. For example, if you want to add line break after '}' character in file data. css, you need to go to open the file in vi editor. Go to command mode, by hitting Esc key.
Opening a blank line: Type o (lower case) to insert, or open, a blank line below the current line. Type O (upper case) to insert a blank line above the current line. Press ESC to get back to command mode.
Vim doesn't show latest newline in the buffer but actually vim always place EOL at the end of the file when you write it, because it standard for text files in Unix systems. You can find more information about this here. In short you don't have to worry about the absence a new lines at the end of the file in vim.
My alternative is using oo
(resp. OO
) to insert a new line under (resp. over) the current through this mapping: nmap oo o<Esc>k
(resp. nmap OO O<Esc>j
)
Yank an empty line and shift-paste it:
Starting with cursor on empty line:
yy + (shift + p)
"yy" yanks the line, and "shift + p" insert it below, without entering insert mode.
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