Fastest way to print a blank line?
How can I print a blank line at some line with one pressing while not in the insert mode?And after that I sh开发者_如何学运维ould still be in normal mode.
In vanilla vim it is o<ESC>
. It is 2 keys to press.
You can also add the following in your .vimrc:
noremap <CR> o<ESC>
to speed up blank line creation with just one single Enter
:).
Press either o or alternatively Shift +o.
To add a blank line after the current line: o (small o) and Escape. To insert a blank line before the current line O (capital O) and Escape. You can skip the Escape if you want to stay in insert mode.
Try this: o - open line
Even though o<ESC>
is just two keypresses, it moves the cursor and adds the creation of new line to change history which might not be desired. That is, the command .
will afterwards repeat creating the new line.
1) unimpaired.vim
There's a plugin, unimpaired.vim, that has a mapping for creating new lines before or after the cursor without changing the change history, and it doesn't move the cursor to the new line. The cursor will also remain in its current column if nostartofline
is set.
Using unimpaired.vim, create a new line after the cursor:
]<Space>
or before the cursor:
[<Space>
http://www.vim.org/scripts/script.php?script_id=1590
It also accepts a count, so to create 3 new lines after the cursor you can use:
3]<Space>
2) Mapping
You can also just make a mapping of your own to create a new line, for example to map \]
(or whatever your leader key is) to add a line after your cursor:
:nnoremap <Leader>] :put!=repeat(nr2char(10),v:count)<Bar>']+1<Cr>
This is how unimpaired.vim creates the new lines. In order to make a similar mapping to create the new line before the cursor, just change the +1 to -1
精彩评论