简体   繁体   English

Textmate:如何输入重复的字符序列?

[英]Textmate: How do I enter a repeated sequence of characters?

I often need to enter text (consisting of repeated characters) like this: 我经常需要输入文字(由重复的字符组成),如下所示:

------------------------------------
 TODO
------------------------------------

In emacs, I can do a 在emacs中,我可以做一个

C-u 60 - 

that's a Ctrl+U followed by a "60" followed by a "-", which makes entering a repeated sequence of characters easy. 这是一个Ctrl + U后跟一个“60”后跟一个“ - ”,这使得输入一个重复的字符序列很容易。

Is there any way to do something like this in TextMate? 有没有办法在TextMate中做这样的事情?

对于您给出的具体示例,您可以键入Ctrl-Shift-B,“TODO”来创建文本横幅。

In TextMate, open the Bundle Editor and select the language you'd like to do this in. (If you'd like to have this functionality in all languages, use the Source bundle) Click the plus symbol at the bottom left, and choose "New Command." 在TextMate中,打开Bundle Editor并选择您要执行此操作的语言。(如果您希望使用所有语言的此功能,请使用Source包)单击左下角的加号,然后选择“新命令。” Chose "Nothing" for the Save field and "Selected Text or Line" for the two input fields. 为“保存”字段选择“无”,为两个输入字段选择“选定的文本或行”。 Then paste this into the Commands field: 然后将其粘贴到“命令”字段中:

#!/usr/bin/python
import sys
commandLine = raw_input("")
tmArgs = commandLine.split()
numberOfArgs = len(tmArgs)
for i in range(eval(tmArgs[0])):
    for j in range(1, numberOfArgs):
        sys.stdout.write(tmArgs[j])

You can then choose a keyboard shortcut to activate this with in the Activation field. 然后,您可以在“激活”字段中选择一个键盘快捷键来激活它。 The way it works is very similar to that emacs command: type the number of characters you want followed by the character. 它的工作方式与emacs命令非常相似:键入要跟随的字符数。 Then select both of them (this step is unnecessary if they're the only text on the line) and press the shortcut key. 然后选择它们(如果它们是线上唯一的文本,则不需要此步骤)并按快捷键。 My script allows you to specify multiple characters to print, delimited by spaces. 我的脚本允许您指定要打印的多个字符,并以空格分隔。 So if you typed 所以,如果你输入

10 - =

and hit the shortcut key, you'd get 并点击快捷键,你会得到

-=-=-=-=-=-=-=-=-=-=

Edit : After thinking about it...here's another version. 编辑 :思考之后......这是另一个版本。 This one will print the string after the number. 这个将在数字后打印字符串。 So for example 所以举个例子

6 -= (space)

prints 版画

-= -= -= -= -= -= 

Here's that version: 这是那个版本:

#!/usr/bin/python
import sys
import string
commandLine = raw_input("")
timesToPrint = eval(commandLine.split()[0])
firstSpace = string.find(commandLine, " ")
for i in range(timesToPrint):
        sys.stdout.write(commandLine[firstSpace + 1:])

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

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