1. 程式人生 > >Ubuntu / Debian / Deepin等 Sublime Text 3 配置C++環境(一鍵編譯&運行,格式化代碼)

Ubuntu / Debian / Deepin等 Sublime Text 3 配置C++環境(一鍵編譯&運行,格式化代碼)

all text handle hand quest urlopen 修改 rip 並運行

配置編譯環境:

進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++環境(一鍵編譯&運行,格式化代碼)