Sublime text 4 GoFmter Posted on 2021-08-12 这几天在学习Go语言,又心血来潮向回去用用Sublime Text,发现已经Sublime Text 4了 = =,安装gofmt又一直不成功,就自己写了小插件, 123456789101112131415161718import sublimeimport sublime_pluginimport subprocessclass GofmterCommand(sublime_plugin.TextCommand): def run(self, edit): fn = self.view.file_name() if not fn or not fn.endswith('.go'): print('not go file') else: print('find go file') print('ok') si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW output = subprocess.check_output(['gofmt.exe', '%s' % (fn)], startupinfo=si) print(output) r = sublime.Region(0, self.view.size()) self.view.replace(edit, r, output.decode('utf-8')) 可以添加快捷键,将command直接设为gofmter就行了。