LoginSignup
2
2

More than 5 years have passed since last update.

SublimeText2のプラグインを作ってみた

Last updated at Posted at 2013-04-30

ペースト時にクリップボード中の「%s」を選択している箇所の文字列と置換してペーストする

クリップボード中に「ほげほげ%sふがふが」こういう文字列があるとき、
文字列「hogehoge」を選択した状態でCtrl+bを行うと
「ほげほげhogehgoeふがふが」のような形でペーストするだけのプラグインを習作として作ってみました。

プラグイン本体(python)

ReplePaste.py
import sublime, sublime_plugin

class RepleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        clip = sublime.get_clipboard()
        for sel in self.view.sel():
            if not sel.empty():
                rep = clip % self.view.substr(sel)
                self.view.replace(edit, sel, rep)

キーマップ

Default.sublime-keymap
[  
    {  
        "keys": ["ctrl+b"], "command": "reple"  
    }  
]
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2