Vim 命令在正常模式下插入空行 [英] Vim command to insert blank line in normal mode

查看:107
本文介绍了Vim 命令在正常模式下插入空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vim 中是否有任何命令可以与 oO 执行相同的操作(在当前命令之前/之后插入一个空行),但没有t 也切换到插入模式?

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?

推荐答案

:nnoremap <silent> [<space> :pu! _<cr>:']+1<cr>
:nnoremap <silent> ]<space> :pu _<cr>:'[-1<cr>

解释:

  • :put 将在下面逐行粘贴一个寄存器.(:pu! 上面)
  • :pu _ 会粘贴黑洞寄存器,它是空的,所以我们得到一个空行
  • '['] 标记设置在更改或抽出的文本的开头和结尾.
  • :'[ 将光标移动到最后一次更改的起始行(本例中为 put)
  • :'[-1 将移动 '[ 但上移一行
  • :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 line

如果你更喜欢插件,那么我建议 Tim Pope 的 unimpaired.vim.它提供了这些映射,但也需要计数.该插件还有许多其他不错的映射.

If 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.

这篇关于Vim 命令在正常模式下插入空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆