windows 下 sublime text 2 配置 C/C++ 环境
个人认为写代码的话最好还是一款轻便的编辑器,插件功能和界面都是需要合口味的。当经过推荐用了 sublime text 之后感觉这些都完美的满足了。
这里记录下 sublime text 2 的配置方法,因为 sublime text 3 不会弄 sublimeClang 插件所以一直用 ST2。
配置其实很简单,分为 4 个步骤
1.安装ST2
2.安装配置package control
3.安装配置插件
4.编译选项
1.略
2.打开ST2, 通过ctrl + ~打开控制台,键入安装代码
import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')
上面是ST2 的安装代码,ST3 可以进入 package control.io 查看代码。
3.安装配置插件
ctrl+shift+p 中 输入 install package 进入插件列表,有很多插件供选择,我这里只列出了我觉得有必要的插件
1):sublimeClang
安装好之后 进入 sublimeClang 的 USERS 的配置文件
{ "show_output_panel": true, "dont_prepend_clang_includes": true, "inhibit_sublime_completions": false, "automatic_completion_popup": false, "enable_fast_completions": false, "options": [ "-ferror-limit=0", "-D__GNUC__=4", "-D__MSVCRT__", "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/", "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1", "-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/", "-Wno-deprecated-declarations",
// 下面开始是 G++ 的安装路径,根据自己的改一下就可以了
"-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include", "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++", "-isystem", "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++\\mingw32", "-isystem", "C:\\MinGW\\include", "-isystem", "/usr/include", "-isystem", "/usr/include/c++/*", "-Wall" ] }
2) :BracketHighlier
3) :ConverttoUTF8
4. 编译选项
通过preferences -> browse packages 可以找到C++ 文件中的C++.sublime-build文件,贴一下我的编译选项
{ "cmd": ["g++", "${file}", "-o", "${file_path\\}${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "encoding":"UTF-8", "encoding": "cp936", "shell": true, "variants": [ { "name": "Run", "cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path\\}${file_base_name}", "&&", "start", "cmd", "/k", "${file_path\\}${file_base_name} &&echo. & pause && exit"] } ] }
这样就能用来写 C/C++ 了, 个人感觉还是挺好用的