简体   繁体   English

如何在TextMate中多次执行动作(Emacs和Vim都可以轻松完成!)?

[英]How can I perform an action n-many times in TextMate ( both Emacs and Vim can do it easily! )?

Emacs : CU (79) # » a pretty 79 character length divider EmacsCU (79) # »一个漂亮的79字符长度分频器

VIM : 79-i-# » see above VIM79-i-# »见上文

Textmate : ???? Textmate :????

Or is it just assumed that we'll make a Ruby call or have a snippet somewhere? 或者只是假设我们会在某个地方进行Ruby调用或有一个片段?

I would create a bundle command to do this. 我会创建一个bundle命令来执行此操作。

You can take editor selection as input to your script, then replace it with the result of execution. 您可以将编辑器选择作为脚本的输入,然后将其替换为执行结果。 This command, for example, will take a selected number and print the character '#' that number of times. 例如,此命令将采用选定的数字并打印次数“#”。

python -c "print '#' * $TM_SELECTED_TEXT"

Of course this example doesn't allow you to specify the character, but it gives you an idea of what's possible. 当然这个例子不允许你指定角色,但是它让你知道什么是可能的。

Inspired by the other answers. 灵感来自其他答案。 Make a snippet with the following: 制作以下代码段:

`python -c "print ':'.join('$TM_SELECTED_TEXT'.split(':')[:-1]) * int('$TM_SELECTED_TEXT'.split(':')[-1])"`

and optionally assign a key sequence to it, eg CTRL-SHIFT-R 并可选择为其分配一个键序列,例如CTRL-SHIFT-R

If you type -x:4 , select it, and call the snippet (by it's shortcut for example), you'll get "-xxxx". 如果你输入-x:4 ,选择它,然后调用代码段(例如,通过它的快捷方式),你会得到“-xxxx”。

You can also use ::4 to obtain "::::". 您也可以使用::4来获取“::::”。

The string you repeat is enclosed in single quotes, so to repeat ', you have to use \\'. 你重复的字符串用单引号括起来,所以要重复',你必须使用\\'。

By taking the 通过采取

python -c "print '#' * $TM_SELECTED_TEXT"

a step further, you can duplicate the examples you gave in the question. 更进一步,您可以复制您在问题中提供的示例。

Just make a snippet, called divider or something, set the tab trigger field to something appropriate '--' for example, then enter something like: 只需制作一个片段,称为分隔符或其他东西,将tab trigger字段设置为适当的'--' ,然后输入如下内容:

`python -c "print '_' * $TM_COLUMNS"`

Then when you type --⇥ (dash dash tab), you should get a divider of the correct width. 然后当您键入 - --⇥ (破折号破折号选项卡)时,您应该获得正确宽度的分隔符。

True, you've lost some of the terseness that you get from vim, but this is far easier to reuse, and you only have to type it once. 没错,你已经失去了从vim获得的一些简洁性,但是重用起来要容易得多,你只需输入一次即可。 You can also use whatever language you like. 您也可以使用您喜欢的任何语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM