Sublime Text 2配置

gedit用了很久,终于换编辑器了T_T

Sublime Text 自行百度谷歌。

一开始我在官网下载的压缩包,然后自己配置。搞了半天后果断删掉。。。还是用源的自动安装吧。T_T

恩。下面的命令

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2

然后安装好就是咱们的st了。

可是你发现了啥没。。不能输入中文。囧

1、解决Sublime Text 2中文输入问题

解决:(https://www.sinosky.org/linux-sublime-text-fcitx.html)以下大部分抄自这里

1. 保存下述代码为 sublime-imfix.c 文件

/*
sublime-imfix.c
Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
By Cjacker Huang

gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
LD_PRELOAD=./libsublime-imfix.so subl
*/
#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);
}

2. 安装 C/C++ 的编译环境和 gtk libgtk2.0-dev

sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev

3. 编译共享内库

gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC

4.移动编译后的库文件到st目录

sudo cp ./libsublime-imfix.so /opt/sublime_text_2/

5.修改 /usr/share/applications/sublime-text-2.desktop 为

[Desktop Entry]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text_2/libsublime-imfix.so /opt/sublime_text_2/sublime_text %F
[...]

[Desktop Action Window]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text_2/libsublime-imfix.so /opt/sublime_text_2/sublime_text -n
[...]

[Desktop Action Document]
[...]
Exec=env LD_PRELOAD=/opt/sublime_text_2/libsublime-imfix.so /opt/sublime_text_2/sublime_text --command new_file
[...]

6. 修改 /usr/bin/subl 为

#!/bin/sh
export LD_PRELOAD=/opt/sublime_text_2/libsublime-imfix.so
exec /opt/sublime_text_2/sublime_text "[email protected]"

7.搞定,收工。

这样无论从命令行还是桌面快捷键都能够使用中文了~

2、配置Sublime Text 2使得能够编译c++及运行

打开菜单 -> Tools -> Build System -> New Build System...

编辑如下(我自己的配置,其它的大家自己模仿):

{
	"cmd": ["bash", "-c", "echo ‘============building============‘ && g++ ‘${file}‘ -o ‘${file_path}/${file_base_name}‘ -Wall && echo && echo ‘============successful!============‘"],
	//"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-Wall"],
	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
	"working_dir": "${file_path}",
	"selector": "source.c, source.c++",

	"variants":
	[
		{
			"name": "Run",
		//	"cmd": ["bash", "-c", "echo ‘============running============‘ && ‘${file_path}/${file_base_name}‘"]
			"cmd": ["bash", "-c", "echo ‘running...‘ && ‘/home/iwtwiioi/sublime/runbyfile.sh‘ ‘${file_path}‘ ‘${file_base_name}‘"]
		},
		{
			"name": "Runbyter",
		//	"cmd": ["bash", "-c", "echo ‘============running============‘ && ‘${file_path}/${file_base_name}‘"]
			"cmd": ["bash", "-c", "echo ‘running...‘ && ‘/home/iwtwiioi/sublime/cpp-run.sh‘ ‘${file_path}‘ ‘${file_base_name}‘"]
		},
		{
			"name": "buildby",
			//g++ ‘${file}‘ -o ‘${file_path}/${file_base_name}‘ -Wall
			"cmd": ["bash", "-c", "echo ‘============c++11 building============‘ && g++ ‘${file}‘ -o ‘${file_path}/${file_base_name}‘ -Wall -std=c++11 && echo && echo ‘============successful!============‘"]
		}
	]
}

然后那两个文件 cpp-run.sh 和 runbyfile.sh 如下

cpp-run.sh:

#!/bin/bash
# $1 is the execute program
echo "============output============"
dr=$1
nm=$2
pro="$dr/$nm"
dat="$dr/in"
"$pro" < "$dat"
echo
echo

runbyfile.sh:

#!/bin/bash
dr=$1
nm=$2
pro="$dr/$nm"
rin="$dr/in"
rout="$dr/out"
"$pro" < "$rin" > "$rout"
echo
echo "successful!"

然后是配置快捷键:

打开菜单 -> Preferences -> Key Bindings - User

编辑为:

[
	{ "keys": ["f5"], "command": "build"},
	{ "keys": ["f4"], "command": "build", "args": {"variant": "Run"} },
	{ "keys": ["f3"], "command": "build", "args": {"variant": "Runbyter"} },
	{ "keys": ["alt+f5"], "command": "build", "args": {"variant": "buildby"} }
]

收工~

Sublime Text 2配置

时间: 2024-10-28 07:18:10

Sublime Text 2配置的相关文章

Sublime Text 3 配置分析 --摘录于http://www.educity.cn/wenda/150004.html

Sublime Text 3 配置解释(默认){// 设置主题文件“color_scheme”: “Packages/Color Scheme – Default/Monokai.tmTheme”,// 设置字体和大小“font_face”: “Consolas”,“font_size”: 12,// 字体选项:no_bold不显示粗体字,no_italic不显示斜体字,no_antialias和no_antialias关闭反锯齿// subpixel_antialias和no_round是OS

sublime text 3 配置、插件、快捷键

sublime text 3 注册: -– BEGIN LICENSE -– Ryan Clark Single User License EA7E-812479 2158A7DE B690A7A3 8EC04710 006A5EEB 34E77CA3 9C82C81F 0DB6371B 79704E6F 93F36655 B031503A 03257CCC 01B20F60 D304FA8D B1B4F0AF 8A76C7BA 0FA94D55 56D46BCE 5237A341 CD837F

Sublime Text 3 配置 PHPCS 插件

Download php code sniffer addon via Package Control in ST3. Download The php-cs-fixer File From This Website => cs.sensiolabs.org/ (Direct Link => cs.sensiolabs.org/get/php-cs-fixer.phar) Copy Downloaded File To Your php.exe directory (mine is C:/XA

sublime text 3 配置python IDE

Python越来越受“程序猿”们的青睐.快速的开发模式,简洁的代码格式,海量的扩展,这无疑都为python的火热奠定了基础. “磨刀不误砍柴工”,一款功能强劲的IDE能帮助开发者有效的管理.编辑,运行工程代码.Python的开发IDE比较常用的Eclipse + Pydev.JetBrains的Pycharm[收费]等,神级代码编辑软件 Sublime text 3因其强大的代码编辑能和便捷海量的插件而著称. Sublime text 3 也可以配置成Python的IDE,而且经过小编亲测,效果

让你的sublime text能写C代码 (sublime text 2 配置构建C开发环境)

原理 1. 首先你要配置可以编译C++/C环境 2. window中配置该运行环境的环境变量,可以全局使用 3. sublime Text创建新的构建机制,并设置用改全局编译环境 详细过程 可以编译C/C++环境,我们安装MinGW可以先到我的网盘上下载mingw-get-setup然后安装.我都是默认安装的,安装后的路径是C:\MinGW 在window环境变量中设置MinGW的路径,具体可以看贴吧某贴.然后检查是否在window可以使用g++了.在cmd中敲打g++ -v命令,如果出现g++

Sublime Text 3 配置分析

Sublime Text 3 配置解释(默认){// 设置主题文件“color_scheme”: “Packages/Color Scheme – Default/Monokai.tmTheme”,// 设置字体和大小“font_face”: “Consolas”,“font_size”: 12,// 字体选项:no_bold不显示粗体字,no_italic不显示斜体字,no_antialias和no_antialias关闭反锯齿// subpixel_antialias和no_round是OS

让你的sublime text写C代码 (sublime text 2 配置构建C开发环境)

原则 1. 首先你要配置能够编译C++/C环境 2. window中配置该执行环境的环境变量,能够全局使用 3. sublime Text创建新的构建机制.并设置用改全局编译环境 具体过程 能够编译C/C++环境.我们安装MinGW能够先到我的网盘上下载mingw-get-setup然后安装.我都是默认安装的.安装后的路径是C:\MinGW 在window环境变量中设置MinGW的路径,详细能够看贴吧某贴.然后检查是否在window能够使用g++了.在cmd中敲打g++ -v命令.假设出现g++

Sublime Text 3 配置c/c++编译环境(转)

sublime text 3提供了构建功能,它的构建系统(Build systems)可以运行一段外部命令,还可以捕获输出并显示. 要在sublime text 3中实现c或c++代码的编译和运行,在本质上说也是调用外部的命令,windows中也可以理解为执行一段cmd命令. 目前c/c++编译器最流行的就是gcc和g++,本文将从MinGW开始,介绍gcc和g++的基本命令格式,然后详细介绍sublime中自带的编译配置文件,分析每一行的作用.然后给出win7 64bit下 Sublime T

Sublime Text 3配置C++编译运行

因为喜欢Sublime Text 3 的高亮配色,于是想在这里写程序.从emacs配置时连配置文件在哪都不知道到vim配置了半天很有成就感,我对配置文件算是更了解了.不过Sublime Text 3 没那么麻烦.配置C++编译运行的方法大概就是配置一个Build System.在cmd窗口运行且解决了中文乱码问题的c++编译配置如下: { "encoding": "utf-8", "working_dir": "$file_path&q