首页 > 代码库 > Ubuntu / Debian / Deepin等 Sublime Text 3 配置C++环境(一键编译&运行,格式化代码)
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打开可以修改快捷键
Ubuntu / Debian / Deepin等 Sublime Text 3 配置C++环境(一键编译&运行,格式化代码)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。