码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu 14 安装和配置Sublime Text 3

时间:2015-05-02 16:42:07      阅读:249      评论:0      收藏:0      [点我收藏+]

标签: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,之后回车。
稍等一会就会弹出安装插件的窗口,输入想要的插件,回车即可安装。

  1. ConvertToUTF8 :支持UTF8编码的一个插件, 一般解决中文乱码问题,Sublime Text3 这个插件无法正常工作,用Codecs33代替
  2. C / C++:SublimeAStyleFormat C, C++, Cuda-C++, OpenCL, C#, and Java 代码格式工具,快捷键
    Ctrl+Alt+F: Format current file.
    Ctrl+K, Ctrl+F: Format current selection.
  3. Bracket Highlighter 高亮显示匹配的括号、引号和标签。

无法输入中文问题

默认已安装搜狗拼音,增加 /opt/sublime_text 目录下添加sublime_imfix.c

cd /opt/sublime_text
sudo touch sublime_imfix.c
sudo gedit 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 at i-soft.com.cn>

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/gtk.h>
#include <gdk/gdkx.h>
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); 
}

然后输入以下命令

sudo apt-get install build-essential libgtk2.0-dev
sudo 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.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 /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 /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 /opt/sublime_text/sublime_text‘ --command new_file
OnlyShowIn=Unity;

重启Sublime Text3, 解决。

Ubuntu 14 安装和配置Sublime Text 3

标签:sublime   ubuntu-14   

原文地址:http://blog.csdn.net/zwhlxl/article/details/45439947

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!