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 就行了)結果如圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM