標籤:sublime ubuntu-14
安裝Sublime Text 3
sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo apt-get install sublime-text-installer
安裝Package Control
Package Control是一個用於管理外掛程式的好工具,可以用於安裝、刪除、禁用相應的外掛程式,常用的外掛程式都能在上面找到。選擇菜單 view->show console, 然後在控制台視窗輸入下面的python代碼
import urllib.request,os;pf=‘Package Control.sublime-package‘;ipp=sublime.installed_packages_path();os.makedirs(ipp) if not os.path.exists(ipp) else None;open(os.path.join(ipp,pf),‘wb‘).write(urllib.request.urlopen(‘http://sublime.wbond.net/‘+pf.replace(‘ ‘,‘%20‘)).read())
按enter鍵之後,等待完成,完成之後重啟Sublime Text3 軟體。
安裝外掛程式
按下Ctrl+Shift+P,開啟外掛程式管理器,接著輸入Install,之後斷行符號。
稍等一會就會彈出安裝外掛程式的視窗,輸入想要的外掛程式,斷行符號即可安裝。
- ConvertToUTF8 :支援UTF8編碼的一個外掛程式, 一般解決中文亂碼問題,Sublime Text3 這個外掛程式無法正常工作,用Codecs33代替
- C / C++:SublimeAStyleFormat C, C++, Cuda-C++, OpenCL, C#, and Java 代碼格式工具,快速鍵
Ctrl+Alt+F: Format current file.
Ctrl+K, Ctrl+F: Format current selection.
- Bracket Highlighter 高亮顯示匹配的括弧、引號和標籤。
無法輸入中文問題
預設已安裝搜狗拼音,增加 /opt/sublime_text 目錄下添加sublime_imfix.c
cd /opt/sublime_textsudo touch sublime_imfix.csudo gedit sublime_imfix.c
將下面的代碼粘貼進去,儲存
/*sublime-imfix.cUse LD_PRELOAD to interpose some function to fix sublime input method support for linux.By Cjacker Huang <jianzhong.huang at i-soft.com.cn>gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPICLD_PRELOAD=./libsublime-imfix.so sublime_text*/#include <gtk/gtk.h>#include <gdk/gdkx.h>typedef GdkSegment GdkRegionBox;struct _GdkRegion{ long size; long numRects; GdkRegionBox *rects; GdkRegionBox extents;};GtkIMContext *local_context;voidgdk_region_get_clipbox (const GdkRegion *region, GdkRectangle *rectangle){ g_return_if_fail (region != NULL); g_return_if_fail (rectangle != NULL); rectangle->x = region->extents.x1; rectangle->y = region->extents.y1; rectangle->width = region->extents.x2 - region->extents.x1; rectangle->height = region->extents.y2 - region->extents.y1; GdkRectangle rect; rect.x = rectangle->x; rect.y = rectangle->y; rect.width = 0; rect.height = rectangle->height; //The caret width is 2; //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret. if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) { gtk_im_context_set_cursor_location(local_context, rectangle); }}//this is needed, for example, if you input something in file dialog and return back the edit area//context will lost, so here we set it again.static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context){ XEvent *xev = (XEvent *)xevent; if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) { GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window"); if(GDK_IS_WINDOW(win)) gtk_im_context_set_client_window(im_context, win); } return GDK_FILTER_CONTINUE;}void gtk_im_context_set_client_window (GtkIMContext *context, GdkWindow *window){ GtkIMContextClass *klass; g_return_if_fail (GTK_IS_IM_CONTEXT (context)); klass = GTK_IM_CONTEXT_GET_CLASS (context); if (klass->set_client_window) klass->set_client_window (context, window); if(!GDK_IS_WINDOW (window)) return; g_object_set_data(G_OBJECT(context),"window",window); int width = gdk_window_get_width(window); int height = gdk_window_get_height(window); if(width != 0 && height !=0) { gtk_im_context_focus_in(context); local_context = context; } gdk_window_add_filter (window, event_filter, context); }
然後輸入以下命令
sudo apt-get install build-essential libgtk2.0-devsudo gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
編輯Sublime Text3的捷徑
sudo gedit /usr/share/applications/sublime-text.desktop
替換為以下內容
[Desktop Entry]Version=1.0Type=ApplicationName=Sublime TextGenericName=Text EditorComment=Sophisticated text editor for code, markup and proseExec=bash -c ‘LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text‘ %FTerminal=falseMimeType=text/plain;Icon=sublime-textCategories=TextEditor;Development;Utility;StartupNotify=trueActions=Window;Document;X-Desktop-File-Install-Version=0.22[Desktop Action Window]Name=New WindowExec=bash -c ‘LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text‘ -nOnlyShowIn=Unity;[Desktop Action Document]Name=New FileExec=bash -c ‘LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so /opt/sublime_text/sublime_text‘ --command new_fileOnlyShowIn=Unity;
重啟Sublime Text3, 解決。
Ubuntu 14 安裝和配置Sublime Text 3