Sublime Text 3 (含:配置 C# 编译环境)
Sublime Text 3
http://www.sublimetext.com/3
http://www.sublimetext.com/3dev
1. 关闭自动更新
菜单:Preferences->Settings User,打开User配置文档,在大括号内加入(或更改):
"update_check": false
保存关闭文件。重启软件即可。
2. 安装Package Control
按Ctrl+`快捷键或者通过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())
如果顺利的话,此时就可以在Preferences菜单下看到Package Settings和Package Control两个菜单了。重启软件即可。
3. 安装插件:
Preferences->Package Control(或者按Command+Shift+P)
输入:install package 回车
然后输入插件名称,找到插件按回车或者点击,即安装。
卸载插件:
Preferences->Package Control(或者按Command+Shift+P)
输入:remove package 回车
然后输入插件名称,找到插件按回车或者点击,即卸载。
【常用插件】
* Markdown Preview
描述:用浏览器预览Markdown格式文档。
用法:按Command+Shift+P,输入Preview in Browser即可中浏览器中看到预览效果了。
* ConvertToUTF8
描述:支持更多的文件编码格式,解决ANSI乱码问题。
用法:打开或保存文件时就能自动识别中文文字。
* IMESupport(Windows)
描述:Windows平台下的输入法框光标跟谁。
【代码插件】
* SublimeCodeIntel
描述:非常强大的代码提示插件。
* Emmet
描述:前身是 Zen Coding。它让编写 HTML 代码变得简单。
用法:输入简写形式,然后按 Tab 键。
* ColorPicker
描述:颜色拾取器插件。
用法:Command+Shift+P,输入colorpicker
【界面】
* SideBarEnhancements
侧边栏右键菜单增强工具。
【快捷键】
* KeyMaps
4. 添加C#支持(Windows)
1) 配置环境变量 Path
C# 6.0
C:\Program Files (x86)\MSBuild\14.0\Bin
C# 5.0
C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v4.0.30319
详细步骤参考:http://www.cnblogs.com/Bob-wei/p/4669793.html
2)添加 CSharp Build 配置
Tools -> Build System -> New Build System...
粘贴:
{ "shell_cmd": "csc /out:\"${file_path}/${file_base_name}.exe\" \"${file}\"", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.cs", "variants": [ { "name": "Build & Run", "shell_cmd": "csc /out:\"${file_path}/${file_base_name}.exe\" \"${file}\" && start \"${file_base_name}.exe\" /d \"${file_path}\" \"${file_base_name}.exe\"", "working_dir": "${file_path}" }, { "name": "Run", "shell_cmd": "start \"${file_base_name}.exe\" /d \"${file_path}\" \"${file_base_name}.exe\"", "working_dir": "${file_path}" }, { "name": "Build (Form)", "shell_cmd": "csc /t:winexe /r:System.Windows.Forms.dll;System.Drawing.dll /out:\"${file_path}/${file_base_name}.exe\" \"${file}\"", "working_dir": "${file_path}" }, { "name": "Build & Run (Form)", "shell_cmd": "csc /t:winexe /r:System.Windows.Forms.dll;System.Drawing.dll /out:\"${file_path}/${file_base_name}.exe\" \"${file}\" && start \"${file_base_name}.exe\" /d \"${file_path}\" \"${file_base_name}.exe\"", "working_dir": "${file_path}" }, { "name": "Run (Form)", "shell_cmd": "start \"${file_base_name}.exe\" /d \"${file_path}\" \"${file_base_name}.exe\"", "working_dir": "${file_path}" }, ] }
保存为csharp.sublime-build
然后编辑.cs文件,就可以按Ctrl+Shift+B(Tools -> Build With...),选择编译方法,按Ctrl+B(Tools -> Build)进行编译了。
测试:新建一个 test.cs 文件,内容如下。
using System; using System.Drawing; using System.Windows.Forms; class Program { [STAThread] static void Main() { const string _title = "nguid"; var counter = 1; var form = new Form{ Text = _title, ClientSize = new Size(318, 188), AutoScaleDimensions = new SizeF(6F, 12F), AutoScaleMode = AutoScaleMode.Font, }; form.Load += (ss,se) => ((Form)ss).Activate(); var textBox = new TextBox { Font = new Font("Calibri",10), Multiline = true, Location = new Point(12,12), Size = new Size(294, 135), ReadOnly = true, TabIndex = 10, ScrollBars = ScrollBars.Vertical, Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right, Text = string.Format("{0}.\r\n{1}\r\n", counter++, NewGuid()), BackColor = SystemColors.Window, }; textBox.Click += (ss,se) => { var line = textBox.GetLineFromCharIndex(textBox.SelectionStart); if(line>=0 && line<textBox.Lines.Length) { var guidString = textBox.Lines[line]; if (string.IsNullOrWhiteSpace(guidString)){ Clipboard.Clear(); form.Text = _title; } else { Clipboard.SetText(guidString); form.Text = string.Format("{0} - {1}", _title, guidString); } } }; form.Controls.Add(textBox); var button = new Button{ Location = new Point(12,153), Size = new Size(75, 23), TabIndex = 1, Anchor = AnchorStyles.Bottom | AnchorStyles.Left, Text = "&Generate", }; button.Click += (ss,se) => { textBox.Text = string.Format("{0}\r\n{1}.\r\n{2}\r\n", textBox.Text, counter++, NewGuid()); textBox.SelectionStart = textBox.Text.Length; textBox.ScrollToCaret(); }; form.Controls.Add(button); button = new Button{ Location = new Point(100,153), Size = new Size(75, 23), TabIndex = 2, Anchor = AnchorStyles.Bottom | AnchorStyles.Left, Text = "&Clear", }; button.Click += (ss,se) => textBox.Text = ""; form.Controls.Add(button); button = new Button{ Location = new Point(190,153), Size = new Size(75, 23), TabIndex = 3, Anchor = AnchorStyles.Bottom | AnchorStyles.Left, Text = "C&lose", }; button.Click += (ss,se) => form.Close(); form.Controls.Add(button); Application.Run(form); } public static string NewGuid(){ var guid = Guid.NewGuid(); return string.Format("{0:N}\r\n{0:D}\r\n{0:B}\r\n{0:P}", guid); } }
按 Ctrl+Shift+B 选择 csharp - Build & Run (Form) (下次直接按 Ctrl+B 就行了)结果如图: