Ubuntu / Debian / Deepin等 Sublime Text 3 配置C++环境(一键编译&运行,格式化代码)

配置编译环境:

进sublime,然后点击Tools->Build System->New build System

直接用下面的替换

{  
    "shell_cmd": "g++ '${file}' -o '${file_path}/${file_base_name}'",  
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
    "working_dir": "${file_path}",  
    "selector": "source.c, source.c++",  
  
    "variants":  
    [  
        {  
            "name": "Build & Run",  
            "shell_cmd": "x-terminal-emulator  -e bash -c \"g++ '${file}' -o '${file_path}/${file_base_name}' ; '${file_path}/${file_base_name}' ; read -p '\nPress ENTER or type command to continue...'\""  
        },  
  
        {  
            "name": "Build Only",  
            "shell_cmd": "g++ '${file}' -o '${file_path}/${file_base_name}'"  
        },  
  
        {  
            "name": "Run Only",  
            "shell_cmd": "x-terminal-emulator  -e bash -c \"'${file_path}/${file_base_name}' ; read -p '\nPress ENTER or type command to continue...'\""  
        }  
    ]  
}  

  保存文件,文件名任意

  每次使用前,我们按Ctrl+shift+B来选择编译选项

配置一键编译&运行快捷键

点击Preferences->Key Buildings - User

[  
    { "keys": ["ctrl+d"], "command": "duplicate_line" },  
    { "keys": ["alt+up"], "command": "swap_line_up" },  
    { "keys": ["alt+down"], "command": "swap_line_down" },
    { "keys": ["f9"], "command": "build", "args": {"variant": "Build & Run"}},
]  

  分别是复制代码,上移,下移,一键编译并运行

安装格式化插件

首先需要安装Package Control

点击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())

  

安装成功后,按Ctrl+Shift+P,然后输入install,选Package Control: Install Package

然后输入CoolFormat并安装

点击Preferences->Browse Packages,然后进CoolFormat,里面有个Default.sublime-keymap打开可以修改快捷键

 

posted @ 2017-08-13 21:23 Kearon 阅读(...) 评论(...) 编辑 收藏