系统相关
首页 > 系统相关> > Ubuntu20.04下设置Sublime Text4为C轻量级IDE

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进行运行。搞定!

 

标签:Ubuntu20.04,https,Text4,apt,Build,file,path,轻量级,name
来源: https://www.cnblogs.com/mocuishle/p/15824805.html