当我删除标记所在的行时,使 vim 保持标记 [英] Make vim keep mark when I delete the line the mark is on
问题描述
当我删除标记所在的行时,如何让vim保留标记(即,自动将标记移动到标记行正上方或下方的行)
How can I get vim to preserve marks when I delete the line the mark is on (i.e., automatically move the mark to the line immediately above or below the marked line)
推荐答案
也许最简单的方法是在您不想删除它们时使用大写字母标记.如果标记所在的行被删除,则会移动到下一行.
Maybe the easiest way is to use capital letter marks when you don't want them deleted. If the line the mark is on is deleted, it gets moved to the next line.
另一个选项是 lockmarks
命令.lockmarks
接受一个命令来运行并将大多数标记锁定在其当前行号,直到命令完成.如果你想经常这样做,你可能需要为你添加一些 lockmarks
的映射,例如这将 dd
变成标记保留:
Another option is the lockmarks
command. lockmarks
takes a command to run and locks most marks at their current line number until the command completes. If you wanted to do that often, you'd probably need to add some mappings that would lockmarks
for you, for example this turns dd
into mark-preserving:
nnoremap dd :lockmarks normal! dd<cr>
或
nnoremap dd :lockmarks delete<cr>
问题是您无法为 dd
指定计数.可以通过使用 v:count
来解决这个问题,但是我们需要 execute
来获得插值:
The problem is that you lose the ability to specify a count for dd
. It's possible to get around that by using v:count
, but then we'll need execute
to get that interpolated:
nnoremap dd :<c-u>execute 'lockmarks normal! ' . v:count . 'dd'<cr>
然后你必须为你经常使用的每个删除操作定义一个这样的映射.
And then you'd have to define a mapping like this for every deletion operation you use regularly.
因此,使用大写字母标记可能会更容易.你只需要记住使用它们.
So, probably using capital letter marks will be easier. You'll just have to remember to use them.
这篇关于当我删除标记所在的行时,使 vim 保持标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!