下面由sublime教學專欄跟大家介紹sublime text 3怎麼在Ubuntu下支援中文輸入,希望對需要的朋友有幫助!
- 相關依賴軟體的安裝---sudo apt-get install build-essential libgtk2.0-dev
- 複製下面程式碼到sublime text 3中,並儲存為名為sublime_imfix.c的檔案
/* * sublime-imfix.c * Use LD_PRELOAD to interpose some function to fix sublime input method support for linux. * By Cjacker Huang <jianzhong.huang> * * * gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC * LD_PRELOAD=./libsublime-imfix.so sublime_text */ #include <gtk> #include <gdk> typedef GdkSegment GdkRegionBox; struct _GdkRegion { long size; long numRects; GdkRegionBox *rects; GdkRegionBox extents; }; GtkIMContext *local_context; void gdk_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); }</gdk></gtk></jianzhong.huang>
- 在終端機找到檔案位置,將這個檔案編譯成共用函式庫libsublime-imfix.so----輸入指令
gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk -2.0` -fPIC - 將libsublime-imfix.so拷貝到sublime_text所在資料夾---sudo mv libsublime-imfix.so拷貝到sublime_text所在資料夾---sudo mv libsublime-fix .so /opt/sublime_text/
- 修改檔案/usr/bin/subl的內容---sudo gedit /usr/bin/subl
- 將
#!/bin/sh exec /opt/sublime_text/sublime_text "$@"
- 修改為
#!/bin/sh LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text "$@"
這樣,我們從終端機輸入subl啟動,就能在sublime中輸入中文了!
最後,為了方便我們直接啟動時,也能使用中文輸入,我們需要在終端指令開啟和修改檔案sublime_text.desktop的內容---sudo gedit /usr/share/applications/sublime_text.desktop
[Desktop Entry] Version=1.0 Type=Application Name=Sublime Text GenericName=Text Editor Comment=Sophisticated text editor for code,markup and prose Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text %F" Terminal=false MimeType=text/plain; Icon=sublime-text Categories=TextEditor;Development;Utility; StartupNotify=true Actions=Window;Document; X-Desktop-File-Install-Version=0.22 [Desktop Action Window] Name=New Window Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text -n" OnlyShowIn=Unity; [Desktop Action Document] Name=New File Exec=bash -c "LD_PRELOAD=/opt/sublime_text/libsublime-imfix.so exec /opt/sublime_text/sublime_text --command new_file" OnlyShowIn=Unity;
將內容替換為上面程式碼內容,這樣,我們就大功告成了!當然,為了穩定,我們還是從終端啟動更好!
*註
因為我們會看到兩個圖標,其中一個啟動才是可以輸入中文的,另一個則還是不能輸入
以上是sublime text 3怎麼在Ubuntu下支援中文輸入的詳細內容。更多資訊請關注PHP中文網其他相關文章!

選擇SublimeText還是VSCode取決於個人需求:1.SublimeText適合追求輕量級和高效編輯的用戶,其啟動速度快但需購買許可。 2.VSCode適合需要強大調試和豐富插件的用戶,資源消耗較高但開源且免費。

SublimeText和VSCode在插件生態和擴展性上的表現各有優勢。 SublimeText通過PackageControl管理插件,插件數量較少但質量高,主要使用Python腳本擴展。 VSCode則擁有龐大的Marketplace,插件數量多且更新頻繁,使用TypeScript和JavaScript進行擴展,API更為全面。

SublimeText的許可證價格為$99美元,值得購買,因為:1)它提供高效的編輯體驗,提升工作效率;2)擁有豐富的插件生態系統,滿足個性化需求;3)支持跨平台使用,適用於不同操作系統;4)購買後可獲得持續更新和技術支持。

SublimeText是一款功能強大且高度可定制的編輯器。 1)它支持多種編程語言,提供多行編輯、代碼折疊等功能。 2)用戶可以通過插件和配置文件進行定制,如使用PackageControl管理插件。 3)其底層基於Python,支持多線程和GPU加速,性能優異。 4)基本用法包括快捷鍵操作,高級用法涉及宏和Snippets。 5)常見問題如插件安裝失敗可通過檢查網絡和更新解決。 6)性能優化建議包括清理插件和合理使用緩存。

SublimeText的許可證是永久性的數字密鑰,用於解鎖所有功能並去除試用提示。購買後通過官方網站激活,同一密鑰可用於多設備個人使用,需避免違反使用條款。

PackageControl通過以下步驟提升SublimeText的開發體驗:1.安裝PackageControl,使用幾行命令即可完成。 2.通過快捷鍵或菜單訪問PackageControl,進行插件的安裝、更新和刪除。 3.定期清理和更新插件,優化性能並提升開發效率。通過這些操作,開發者可以專注於編程,提升整體開發體驗。

SublimeText的項目管理功能可以通過以下步驟高效組織和導航代碼庫:1.創建項目文件,使用Project菜單中的SaveProjectAs...保存.sublime-project文件。 2.配置項目文件,指定包含的文件夾和設置,如排除特定文件或設置構建系統。 3.打開項目文件,通過Project菜單中的OpenProject快速加載項目環境。 4.優化項目文件,避免包含過多文件夾,使用排除模式提升導航速度。通過這些步驟,你可以利用SublimeText的項目管理功能,提升開發效率和代碼質量。

使用SublimeText的CommandPalette可以提高工作效率。 1)打開CommandPalette(Ctrl Shift P/Windows/Linux,Cmd Shift P/Mac)。 2)輸入命令關鍵字,如"InstallPackage"或"DarkTheme"。 3)選擇並執行命令,如安裝插件或切換主題。通過這些步驟,CommandPalette能幫助你快速執行各種任務,提升編輯體驗。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

WebStorm Mac版
好用的JavaScript開發工具