作者:4396 | 来源:互联网 | 2023-08-26 10:38
Ioftenneedtoentertext(consistingofrepeatedcharacters)likethis:我经常需要输入文字(由重复的字符组成),如下所示:
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中做这样的事情?
2 个解决方案
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." Chose "Nothing" for the Save field and "Selected Text or Line" for the two input fields. Then paste this into the Commands field:
在TextMate中,打开Bundle Editor并选择您要执行此操作的语言。(如果您希望使用所有语言的此功能,请使用Source包)单击左下角的加号,然后选择“新命令。”为“保存”字段选择“无”,为两个输入字段选择“选定的文本或行”。然后将其粘贴到“命令”字段中:
#!/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. 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
然后,您可以在“激活”字段中选择一个键盘快捷键来激活它。它的工作方式与emacs命令非常相似:键入字符后面要包含的字符数。然后选择它们(如果它们是该行上的唯一文本,则不需要此步骤)并按快捷键。我的脚本允许您指定要打印的多个字符,并用空格分隔。所以,如果你输入
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:])