Ubuntu20.04下设置Sublime Text4为C轻量级IDE

1、首先下载Sublime Text4,官网:https://www.sublimetext.com/docs/linux_repositories.html

按照里面下载指示,下载稳定stable版本:

apt

The apt repository contains packages for both x86-64 and arm64.

Install the GPG key:

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -

Ensure apt is set up to work with https sources:

sudo apt-get install apt-transport-https

Select the channel to use:

Stable
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
Dev
echo "deb https://download.sublimetext.com/ apt/dev/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

Update apt sources and install Sublime Text

sudo apt-get update
sudo apt-get install sublime-text

 

2、打开Sublime Text,依次进入Tools -> Build System -> New Build System,把如下代码拷贝进去:

{
    "cmd" : ["gcc", "$file_name", "-o", "${file_path}/${file_base_name}", "-lm", "-Wall"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "selector" : "source.c, source.c++",
    "shell":false,
    "working_dir" : "$file_path",

    "variants":
    [
        {
            "name": "Build & Run",
            "cmd": ["x-terminal-emulator", "-e", "bash -c \"gcc '${file}' -o '${file_path}/${file_base_name}' -lm -Wall && '${file_path}/${file_base_name}' ; read -p '\nPress any key to continue...'\""]
         },

         {
             "name": "Build Only",
             "cmd": ["gcc", "$file_name", "-o", "${file_path}/${file_base_name}", "-lm", "-Wall", "-g"]
         },

         {
             "name": "Run Only",
             "cmd": ["x-terminal-emulator", "-e", "bash -c \"'${file_path}/${file_base_name}' ; read -p '\nPress any key to continue...'\""]
         }
    ]
}

 

 保存为C.sublime-build,默认路径即可。

 

3、回到主界面,打开C代码文件,依次点击Tools -> Build System -> C,可以使用自己设定的C编译系统了。

 

4、同时按住 Ctrl + Shift + B,就可以选择不用的编译/运行选项,同时按住Ctril + B默认按照上一次的编译命令执行(注意Run Only选项需要先编译代码后才可以执行,否则终端提示找不到可执行文件)。

 

5、以上基本OK了,想偷懒的话继续:

 

6、依次点击:Preferences -> Key Bindings设置快捷键。在中括号中输入以下代码:

{"keys": ["f9"], "command": "build", "args": {"variant": "Build Only"}},
{"keys": ["f10"], "command": "build", "args": {"variant": "Run Only"}},

保存退出。

 

7、打开C源代码文件,按f9进行编译,按f10进行运行。搞定!

 

posted @ 2022-01-20 00:51  Mocuishle007  阅读(193)  评论(0编辑  收藏  举报