Emacs宏生成序列? [英] Emacs macro to generate a sequence?

查看:114
本文介绍了Emacs宏生成序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关如何创建vi宏的文章:
vi序列宏,我看到一个有用的宏在缓冲区中创建一个序列。

I was reading this article on how to create vi macros: vi sequence macro and I saw one useful macro to create a sequence in the buffer.

1。

2.

...

100.

1.
2.
...
100.

vi,诀窍是可以在一个数字上击中ctrl-a,它会添加一个,所以这使得宏变得容易。我想在emacs中做同样的事情。

In vi, the trick is that one can hit ctrl-a over a number and it will add one to it, so this made the macro easy. I want to be able to do the same thing in emacs.

推荐答案

如果你使用Emacs 23(也许22?) ,默认情况下使用 kmacro-insert-counter 绑定到 Cx Ck TAB 。所以,你可以这样做:

If you are using Emacs 23 (and maybe 22?), use kmacro-insert-counter which is bound to C-x C-k TAB by default. So for your example, you'd do:

Cx(Cx Ck TAB。RET Cx)

所以启动宏,插入计数器后跟'。',换行符,结束宏。然后 Cx eeeeeee 等或 M-1 0 0 Cx e 获得100个。

So start macro, insert counter followed by '.', newline, end macro. Then C-x e e e e e e e etc. Or M-1 0 0 C-x e to get 100 of them.

编辑:

忘了提到你可以将计数器设置为初始值。例如从1开始而不是0开始 M-1 Cx Ck Cc

Forgot to mention you can set the counter to an initial value also. For example to start at 1 instead of 0 do M-1 C-x C-k C-c.

如果你不不要让计数器在某个特定的点增加,前缀为 Cu 。在这一点上,当然击键会变得有点可笑,所以我通常用一个键来插入,但不要增加。

And if you don't want the counter to increment at a particular point, prefix it with C-u. Of course the keystrokes are getting a bit ridiculous at this point, so I usually bind a key to insert-but-don't-increment.

这篇关于Emacs宏生成序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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