如何有效清除vim寄存器? [英] How to clear vim registers effectively?

查看:31
本文介绍了如何有效清除vim寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vim 中的寄存器是一个很棒的功能,可以存储文本片段,甚至可以对存储在其中的文本运行命令.不过,我是个很整洁的人,做完后会收拾东西.

Registers in vim are a great feature to store text snippets and even to run commands on the text stored within them. However, I'm a tidy person and tend to clean things up when I'm done.

我知道如果我想清除寄存器 a,我可以使用 qaq.

I know that if I wanted to clear register a, I can use qaq.

我也可以执行以下命令:

I can also execute the following command:

:let @a = ''

然而,这些解决方案似乎只是解决问题的方法.当我执行 :registers 时,列表仍然显示 register a(具有空值),而不会显示从未使用过的寄存器.

However, these solutions seem like a mere workaround to the problem. When I execute :registers, the list still displays register a (with an empty value), while registers that have otherwise never been used are not displayed.

有没有办法清除一个具有从该列表中删除寄存器的副作用的寄存器?

Is there a way to clear a register with the side-effect of removing the register from this list?

如果是这样,是否还有一种方法可以一次清除所有寄存器,即重置该寄存器列表?

And if so, is there also a way to clear all registers at once, i.e., to reset that list of registers?

推荐答案

由于邮件列表中的那个古老的答案,由 @romainl 链接,我们有 setreg('a', []) 清除寄存器.

Since that venerable answer on the mailing list, linked by @romainl, we have setreg('a', []) that clears the register.

因此,代码可以变成:

let regs=split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-"', '\zs')
for r in regs
  call setreg(r, [])
endfor

这篇关于如何有效清除vim寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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