Sublime text3 自用配置

228 阅读1分钟

插件

  • ConvertToUTF8: utf-8 插件
  • Alignment:选中并按ctrl+alt+a就可以使其按照等号对其
  • DocBlockr:自动生成大块的注释
  • CoolFormat:简单好用的代码格式化工具

常用配置

// Display file encoding in the status bar
"show_encoding": true,
// Display line endings in the status bar
"show_line_endings": true,
// The number of spaces a tab is considered equal to
"tab_size": 4,
// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": true,

c语言编译配置

GCC

{
    "cmd": ["gcc", "-O2", "-s","-fexec-charset=gbk", "-o", "${file_path}/${file_base_name}", "${file}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "encoding": "gbk",
    "selector": "source.c",
    "variants": [
        {
            "name": "Run",
            "cmd": [
                "cmd", "/c",
                "gcc", "-O2", "-s","-fexec-charset=gbk", "-o", "${file_path}/${file_base_name}", "${file}",
                "&&", "${file_path}/${file_base_name}"
            ],
        },
        {
            "name": "Run(CMD)",
            "cmd": [
                "cmd", "/c",
                "gcc", "-O2", "-s","-fexec-charset=gbk", "-o", "${file_path}/${file_base_name}", "${file}",
                "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} &echo.&pause"
            ]
        }
    ]
}

TCC

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c",
    "encoding": "gbk",
    "linux":    {"shell_cmd": "tcc -o ${file_path}/${file_base_name} ${file}"},
    "osx":      {"shell_cmd": "tcc -o ${file_path}/${file_base_name} ${file}"},
    "windows":  {"shell_cmd": "tcc -o ${file_path}/${file_base_name}.exe ${file}"},
    "variants": [
        {
            "name": "Run",
            "linux":    {"shell_cmd": "tcc -run ${file}"},
            "osx":      {"shell_cmd": "tcc -run ${file}"},
            "windows":  {"cmd": ["tcc", "-run", "${file}"]},
        },
        {
            "name": "Run(CMD)",
            "linux": {
                "shell_cmd": "gnome-terminal -e 'bash -c \"echo tcc -run ${file};echo;time tcc -run \\\"${file}\\\";echo ;echo Press any key to exit...;read -n 1;exit;\"'"
            },
            "windows": {
                // "shell_cmd": "git-bash -c \"echo tcc -run ${file_name};echo;time winpty tcc -run ${file_name};echo;echo Press any key to exit...;read -n 1;exit;\"",
                "cmd": [
                    "cmd", "/c",
                    "start", "cmd", "/c", "tcc -run ${file} &echo.&pause"
                ],
            },
            "osx": {}
        }
    ]
}

Ubuntu 上配置c语言编译环境

安装:

sudo su
apt-get update
apt-get install gcc
apt-get install build-essential

配置sublime的编译环境

{
    "cmd": ["g++ ${file} -o ${file_base_name}"], 
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": true,
    "variants":
    [
        {
            "name": "Run",
            //"cmd": ["${file_path}/${file_base_name}"]
            "shell_cmd": "gcc \"${file}\" -o \"${file_path}/${file_base_name}\" -Wformat=2 && \"${file_path}/${file_base_name}\""
        },
        {
            "name": "RunInShell",
            // "cmd": ["gnome-terminal -- bash -c '${file_path}/${file_base_name};read' "]
            "cmd": ["gnome-terminal -- bash -c \"gcc ${file} -o ${file_path}/${file_base_name} -lm -Wall; ./${file_base_name};read \""]
            // "cmd": ["gnome-terminal -- bash -c \"g++ ${file} -o ${file_base_name} -lm -Wall; ./${file_base_name}; exec bash\""]
        }
    ]
}