我得到了一个sublime text 3
的插件,它可以让我按其编号将光标移动到一行:
import sublime, sublime_plugin
class prompt_goto_lineCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.show_input_panel("Goto Line:", "", self.on_done, None, None)
pass
def on_done(self, text):
try:
line = int(text)
if self.window.active_view():
self.window.active_view().run_command("goto_line", {"line": line} )
except ValueError:
pass
class go_to_lineCommand(sublime_plugin.TextCommand):
def run(self, edit, line):
# Convert from 1 based to a 0 based line number
line = int(line) - 1
# Negative line numbers count from the end of the buffer
if line < 0:
lines, _ = self.view.rowcol(self.view.size())
line = lines + line + 1
pt = self.view.text_point(line, 0)
self.view.sel().clear()
self.view.sel().add(sublime.Region(pt))
self.view.show(pt)
我想改进它,让我把光标移到包含指定字符串的第一行。这就像是对文件的搜索:
例如,如果pass-to-it字符串"class go_to_lineCommand"
插件必须将光标移到第17行:
并可能选择字符串class go_to_lineCommand
。在
问题归结为找到regionWithGivenString
,然后我可以选择它:
但不知道得到regionWithGivenString
的方法。在
我试过了
但仍然没有结果。在
在API中有它,使用查看.查找(regex,pos)方法。在
http://www.sublimetext.com/docs/3/api_reference.html
我不确定典型的方式。但是,您可以通过以下方式实现:
Region(start, end)
添加到所选内容中。在示例:
对龙华回答的一个可能的改进-在目标线上添加移动光标。在
相关问题 更多 >
编程相关推荐