有没有办法在 Sublime Text 2 中添加插入每个光标递增一次的数字?
例如,以
|
为光标:
Lorem ipsum dolor sit amet, |
vehicula sed, mauris nam eget|
neque a pede nullam, ducimus adipiscing,
vestibulum pellentesque pellentesque laoreet faucibus.|
想要的结果:
Lorem ipsum dolor sit amet, 1|
vehicula sed, mauris nam eget2|
neque a pede nullam, ducimus adipiscing,
vestibulum pellentesque pellentesque laoreet faucibus.3|
此功能是原生存在的,还是有插件提供?
我推荐插件Text Pastry。 数字序列命令就是您所需要的。
我更喜欢使用插入数字命令:
Text Pastry 内置了对插入数字语法的支持 提供由一个空格分隔的三个数字:
N M P
N:起始索引。
M 表示将添加到索引的步长 每个选择。
P 必须 > 0 并且将用于填充索引 前导零。
我认为实现您要求的唯一方法是创建您自己的插件。
Tools/New Plugin...
:
import sublime_plugin
class IncrementSelectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
start_value = int(self.view.substr(self.view.sel()[0]))
counter = 0
for selection in self.view.sel():
self.view.insert(edit, selection.begin(), str(start_value + counter))
counter = counter + 1
for selection in self.view.sel():
self.view.erase(edit, selection)
将其保存在您的
User
目录中。
然后添加一个快捷方式到您的Key Bindings - User
:
{ "keys": ["YOUR_SHORTCUT"], "command": "increment_selection" }
现在您可以将光标放置在您需要的位置:
插入计数器应从的数字(在本例中为 1):
选择您输入的号码 (shift<—):
输入快捷键: