[英]Vim command to insert blank line in normal mode
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? Vim 中是否有任何命令可以与
o
或O
执行相同的操作(在当前行之前/之后插入一个空行),但哪个也不会切换到插入模式?
:nnoremap <silent> [<space> :pu! _<cr>:']+1<cr>
:nnoremap <silent> ]<space> :pu _<cr>:'[-1<cr>
Explanation:解释:
:put
will paste a register linewise below. :put
将在下面逐行粘贴一个寄存器。 ( :pu!
above) :pu!
以上):pu _
will paste the blackhole register, which is empty so we get a blank line :pu _
将粘贴黑洞寄存器,它是空的,所以我们得到一个空行'[
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) :'[
会将 cursor 移动到最后更改的起始行(本例中的 put):'[-1
will move the '[
but up one more line :'[-1
将移动'[
但又向上移动一行If you prefer a plugin then I suggest Tim Pope's unimpaired.vim .如果您更喜欢插件,那么我建议 Tim Pope 的unimpaired.vim 。 Which supplies these mappings, but will also take a count.
它提供了这些映射,但也需要计数。 The plugin also has many other nice mappings.
该插件还有许多其他不错的映射。
In insert mode:在插入模式下:
:normal O
From vim inline manual:来自 vim 内联手册:
Execute Normal mode commands {commands}.
执行正常模式命令 {commands}。 This makes it possible to execute Normal mode commands typed on the command-line.
这使得执行在命令行上键入的正常模式命令成为可能。 {commands} are executed like they are typed.
{commands} 像输入一样执行。 For undo all commands are undone together.
对于撤消,所有命令一起撤消。 Execution stops when an error is encountered.
遇到错误时停止执行。 If the [,] is given.
如果给出 [,]。 mappings will not be used.
不会使用映射。 {commands} should be a complete command, If {commands} does not finish a command.
{commands} 应该是一个完整的命令,如果 {commands} 没有完成一个命令。 the last one will be aborted as if or was typed.
最后一个将被中止,就像或被键入一样。
http://vimdoc.sourceforge.net/htmldoc/various.html#:normal http://vimdoc.sourceforge.net/htmldoc/various.html#:normal
I got the hint there: https://unix.stackexchange.com/a/16452/7914我得到了提示: https://unix.stackexchange.com/a/16452/7914
you can try something like this:你可以尝试这样的事情:
:map <c-j> o<esc>
this is: when you press control + j it will add a line below (and go to insert mode) and then switch back to normal mode if you want to stay in the same line you where before just add a k
at the end, something like this:这是:当你按下control + j时,它会在下面添加一行(以及 go 到插入模式)然后切换回正常模式,如果你想保持在与之前在最后添加一个
k
之前相同的行中,一些东西像这样:
:map <c-j> o<esc>k
I also added a control + k to add a line before the one I's standing on我还添加了一个control + k在我站立的那一行之前添加一行
:map <c-k> O<esc>
and just like the one before you can add a j
at the end to stay on the same line:就像你可以在末尾添加
j
以保持在同一行之前一样:
:map <c-k> O<esc>j
If you need or want something more advanced you can check this posts: Quickly adding and deleting empty lines or Insert newline without entering insert mode如果您需要或想要更高级的东西,您可以查看以下帖子:快速添加和删除空行或在不进入插入模式的情况下插入换行符
dd on a blank line, p to restore it, and then p where you want the blank line(s) dd 在空行上, p 恢复它,然后 p 你想要空行的地方
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.