最近在使用Sublime Text作為一些js等腳本文件的編輯器,,此編輯器相當(dāng)?shù)牟诲e(cuò),,現(xiàn)在插件也是相當(dāng)?shù)亩?,?a href="http://www./tag/%E6%B3%A8%E5%86%8C" target="_blank" title="注冊(cè)">注冊(cè)版本可以無(wú)限制的使用,。當(dāng)然他也有不足,到目前為止官方還不支持GBK系統(tǒng)的編碼,,雖然我們目前大部分項(xiàng)目都是UTF-8的,,但是難免還是會(huì)用到GBK等中文編碼。我安裝了GBK Encoding Support這款插件可以解決打開(kāi)GBK編碼的文件中文亂碼的問(wèn)題,,但是隨之而來(lái)的確是tab顯示的標(biāo)題亂碼了,,不怎么好看,大家可以參看下圖: #coding: utf8 import sublime, sublime_plugin import os, re import urllib TEMP_PATH = os.path.join(os.getcwd(), 'tmp') SEPERATOR = ' ' def gbk2utf8(view): try: reg_all = sublime.Region(0, view.size()) gbk = view.substr(reg_all).encode('gbk') except: gbk = file(view.file_name()).read() text = gbk.decode('gbk') file_name = view.file_name().encode('utf-8') #tmp_file_name = urllib.quote_plus(os.path.basename(file_name)) + SEPERATOR + urllib.quote_plus(file_name) #tmp_file = os.path.join(TEMP_PATH, tmp_file_name) #f = file(tmp_file, 'w') #newline f = file(view.file_name(),'w') f.write(text.encode('utf8')) f.close() window = sublime.active_window() #newline v = window.find_open_file(file_name) #v = window.find_open_file(tmp_file) if(not v): #newline #window.open_file(tmp_file) window.open_file(file_name) window.focus_view(view) window.run_command('close') window.focus_view(v) sublime.status_message('gbk encoding detected, open with utf8.') |
|
來(lái)自: lifei_szdz > 《Tool》