Sublime Text のキー バインドは初めてです。キャレットが行末にない場合、最後にセミコロンを挿入する方法はありますか? マクロでは、次のようになると思います: go to eol -> insert ; -> 戻ってきてください。しかし、カムバック部分を行う方法がわかりません。
ありがとう。
Sublime Text のキー バインドは初めてです。キャレットが行末にない場合、最後にセミコロンを挿入する方法はありますか? マクロでは、次のようになると思います: 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
。あなたのマクロ定義はeofではなくeolであるはずだと思いました。
編集: 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)
上記のコードをわずかに変更します。トグル動作を追加します。したがって、キーの組み合わせを再度呼び出すと、セミコロンが削除されます。これは Sublime Text 3 バージョンです。
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"})
pos = view.sel()[0].begin()
last_chr = view.substr(pos-1)
if last_chr != ';':
view.run_command("insert", {"characters": ";"})
else:
view.run_command("left_delete")
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)
キーボード ショートカットを追加するには、次の行を "Preferences > Key Bindings - User" に挿入します。
{ "keys": ["ctrl+alt+enter"], "command": "semicolon_insert" }