如果我映射 ddkP,Vim 会吃掉我所有的行

发布于 2025-01-02 22:29:57 字数 199 浏览 3 评论 0原文

在 Vim 中,我设置了一个映射,每次按 _ 时都会移动一行

nnoremap _ ddkP

在我的实验中,当我到达 Vim 文件的顶部时,所有如果我继续按住_,线条就会被吃掉,

有什么问题吗?我使用的是 Mac,但使用控制台 Vim,而不是 MacVim。

In Vim, I set a mapping to move a line up with each press of _

nnoremap _ ddkP

In my experiments, when I reach the top of my Vim file, all the lines get eaten up if I continue to press and hold _

Is something wrong? I'm on the Mac, but using the console Vim, not MacVim.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼波传意 2025-01-09 22:29:57

k(上移一行)在文件顶部时失败。我怀疑这会导致映射键执行停止,只剩下 dd (删除当前行)。要解决此问题,您需要一种破坏性较小的方式来移动线路。

The k (move up one line) fails when at the top of a file. I suspect this causes the mapped keys execution to stop, leaving you with just dd (delete current line). To fix this, you'll need a less destructive way to move the line.

心意如水 2025-01-09 22:29:57

克里斯托的解释对我来说看起来很合乎逻辑。

我建议您尝试使用此映射,它会执行 :move而不删除任何行:

:nnoremap _ :move .-2<CR>

您也可以原子地撤消此操作。

Kristo's explanation looks logical to me.

I suggest that you try this mapping instead, which does a :move without deleting any lines:

:nnoremap _ :move .-2<CR>

You can also undo this atomically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文