macros - Sublime Text 绑定(bind) : insert semicolon at eol and come back

标签 macros sublimetext2 key-bindings

我是 Sublime Text 键绑定(bind)的新手。有没有办法,当插入符号不在行尾时,在末尾插入分号?在宏中,我猜它是: go to eol -> insert ; -> 回来。但我不知道如何做回来的部分。

谢谢。

最佳答案

我认为你必须使用一个插件,因为你想恢复以前的位置,尽管我可能是错的。这是一个 ST3 版本。

import sublime
import sublime_plugin

class SemicolonInsertCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        region_name = "original_cursors"
        view = self.view
        view.add_regions(region_name, view.sel())
        view.run_command("move_to", {"extend": False, "to": "eol"})
        view.run_command("insert", {"characters": ";"})
        view.sel().clear()
        cursors = view.get_regions(region_name)
        for cursor in cursors:
            view.sel().add(sublime.Region(cursor.b, cursor.b))
        view.erase_regions(region_name)

使用命令 semicolon_insert 创建键绑定(bind).我假设您的宏定义应该是 eol 而不是 eof。

编辑:
ST2 兼容版本

import sublime
import sublime_plugin

class SemicolonInsertCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        region_name = "original_cursors"
        view = self.view
        view.add_regions(region_name, list(view.sel()), "")
        view.run_command("move_to", {"extend": False, "to": "eol"})
        view.run_command("insert", {"characters": ";"})
        view.sel().clear()
        cursors = view.get_regions(region_name)
        for cursor in cursors:
            view.sel().add(sublime.Region(cursor.b, cursor.b))
        view.erase_regions(region_name)

关于macros - Sublime Text 绑定(bind) : insert semicolon at eol and come back,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16952385/

相关文章:

c - 在c复合语句中使用宏时

c++ - 在没有括号的宏中使用逗号 : How can I mix and match with a template?

java - 在 JTextField 中点击空格键触发父窗口的键绑定(bind)

Java Swing KeyBindings 仅在 Mac 上停止工作

使用下一个代码语句的 C 宏或 GCC 指令

python - 宏程序不起作用

sublimetext2 - 如何在Sublime Text的侧边栏中隐藏具有特定名称的文件?

sublimetext2 - sublhandler.app - 打开,但不打开 sublime 文本

sublimetext2 - 在 Sublime Text 2 中更改配色方案的键盘快捷键?

emacs - 如何在 Emacs 中重新绑定(bind) CUA 模式设置的键?