目标
把代码里面选中的字符直接替换为空格。用于复制粘贴的时候,多行代码快速修改。
代码
import os, sublime, sublime_plugin
class ReplaceCharCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
position = view.sel()[0]
changestr = view.substr(position)
newstr = ''
for c in changestr:
if c != '\n':
newstr += ' '
else:
newstr += c
view.replace(edit,position,newstr)
使用示例
纵向编辑代码得到
assign A = DATA[(`B+`C+0) :+ (`A)];
assign B = DATA[(`B+`C+0) :+ (`B)];
assign C = DATA[(`B+`C+0) :+ (`C)];
选中替换后
assign A = DATA[(`B+`C+0) :+ (`A)];
assign B = DATA[( `C+0) :+ (`B)];
assign C = DATA[( 0) :+ (`C)];