1. Sublime Text 3的下载安装
到官方网站上http://www.sublimetext.com/3下载64位(系统位64位)的.deb安装包(http://c758482.r82.cf2.rackcdn.com/sublime-text_build-3059_amd64.deb),下载后双击安装即可。安装好之后,通过命令subl即可打开程序,此时已经可以编写代码了。
2.安装好软件之后,最好安装package control
方法如下:使用Ctrl+`快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码:
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf),'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
如果顺利的话,此时就可以在Preferences菜单下看到Package Settings和Package Control两个菜单了。
手动安装
可能由于各种原因,无法使用代码安装,那可以通过以下步骤手动安装Package Control:
1.点击Preferences > Browse Packages菜单
2.进入打开的目录的上层目录,然后再进入Installed Packages/目录
3.下载Package Control.sublime-package并复制到Installed Packages/目录
4.重启Sublime Text。
在Ubuntu 14.04中安装了SublimeText 3之后发现既然不支持输入中文,于是在网上搜罗一下,发现很多人遇到了同样的问题,但是解决办法大该就只有一个。下面根据自身的安装及解决办法总结如下:
/*
* 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);
}
SublimeClang是Sublime Text中唯一的C/C++自动补全插件,功能强大,自带语法检查功能,不过最近作者已经停止更新了,
目前只能在Sublime Text 2的Package Control中可以找到并自动安装,在SublimeText 3中只能手动通过源码安装,
其代码线在https://github.com/quarnster/SublimeClang中。具体安装步骤如下:
安装相关软件
sudo apt-get install cmake build-essential clang git(git 是个好东西^-^)
cd ~/.config/sublime-text-3/Packages一切成功的话将会在SublimeClang/internals目录中生成libcache.so库文件。
git clone --recursive https://github.com/quarnster/SublimeClang SublimeClang
cd SublimeClang
cp /usr/lib/x86_64-linux-gnu/libclang-3.4.so.1 internals/libclang.so #这一步很重要,如果你的clang库不是3.4版本的话,请将对应版本的库拷贝到internals中
cd src
mkdir build
cd build
cmake ..
make
重启Sublime Text,然后按快捷键Ctrl + `(Esc下面那个键)打开自带的控制输出,看看有没有错误,如果没有错误就说明一切OK了。接下来就是配置自己的文件了,
按下ctrl + shift + p快捷键,在弹出的输入框中输入 sublimeclang settings ,然后选择带User那一行,在打开的文件中输入如下信息:
{
"show_output_panel": false,
"dont_prepend_clang_includes": true,
"inhibit_sublime_completions": false,
"options":
[
"-std=gnu++11",
"-isystem", "/usr/include",
"-isystem", "/usr/include/c++/*",
"-isystem", "/usr/include/c++/4.8",
"-isystem", "/usr/include/c++/4.8/*",
"-isystem", "/usr/include/boost",
"-isystem", "/usr/include/boost/**",
"-isystem", "/usr/lib/gcc/x86_64-linux-gnu/4.8/include",
"-isystem", "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/*"
]
}
注释:我的gcc版本为4.8,如果你的不是请替换对应的版本,在#include相应的头文件后保存当前文件,在接下来的操作中将更快的提示所包含在头文件的函数或者变量。
----好了到这里就可以高亮显示C/C++代码勒~
4.搭建c/c++编译系统
建立新的编译系统
Tools –> Build System –> New Build System
在打开的页面中粘贴以下代码
{ "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "&", "gnome-terminal", "-x", "bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}' ;read -n1 -p 'press any key to continue.'"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++",}保存一个名字,在Tools->Build-> System 中选中即可.
到此,简单的c/c++ IDE就搭建完毕了,打开一个.c文件后,就会有高亮效果,并且按ctrl + b 就会自动编译运行了。
![]()