比NotePad++更好的文本代码(C#)编辑器Sublime Text

前言

 前两天在博客园看到@晴天猪的博客发表的关于他使用的代码编辑器,自己索性试了一下,果断好用,自己也来记录一下。以便以后配置使用。接下来我配置的主要是简单的编译C#代码的。

配置一调用C#编译器

 我现在电脑的系统为Win7哦。我要将C#编译器的csc.exe文件添加到环境变量中。

首先我的电脑==右键属性==高级系统设置==环境变量==系统变量==变量Path双击==在变量值中将路径添加到后面添加前用;分隔C:\Windows\Microsoft.NET\Framework\v4.0.30319

配置二新建编译器选项

 打开Submile Text

 工具  编译系统   最下面的编译新系统,然后将如下命令斤西瓜复制

{
      "cmd": ["csc", "$file"],
      "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
      "selector": "source.cs",
      "encoding": "cp936"
 }

另存为ST2程序目录的Packages/User文件夹下面,文件名为:C#.sublime-build。

测试编译代码

 下面在ST中编写一些简单的代码如下

using System;
using System.Linq;
class  Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
        Console.ReadLine();
    }
}

将代码随便保存为一个文件后缀为cs哦。然后Ctrl+B就OK了。

现在只能编译,但是不能测试运行。你我们接下来配置一下吧。

配置三能让代码运行起来

 其实很简单,就是在C#编译器路径中我的电脑也就是C:\Windows\Microsoft.NET\Framework\v4.0.30319中创建RunCSharp.bat文件,然后在其中写入以下内容:

@ECHO OFF
 cd %~dp1
 ECHO Compiling %~nx1.......
 IF EXIST %~n1.exe (
 DEL %~n1.exe
 )
 csc %~nx1
 IF EXIST %~n1.exe (
 ECHO -----------OUTPUT-----------
 start %~n1
 )

当然光添加上述文件还不够,还需要修改刚刚在编译器中添加的C#.sublime-build,修改后内容如下:

{
      "cmd": ["RunCSharp.bat", "$file"],
      "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
      "selector": "source.cs",
      "encoding": "cp936"
 }

下面再Ctrl+B一下刚刚写的简单的代码吧

配置四可以给代码添加注释

 C#中的注释快捷键是无效的,这是因为Packages文件夹中缺少了定义注释行为的文件。打开Packages,在C#文件夹中添加一个名为:Comments.tmPreferences文件,输入如下内容:

View Code 
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
     <key>name</key>
     <string>Comments</string>
     <key>scope</key>
     <string>source.cs</string>
     <key>settings</key>
     <dict>
         <key>shellVariables</key>
         <array>
             <dict>
                 <key>name</key>
                 <string>TM_COMMENT_START</string>
                 <key>value</key>
                 <string>// </string>
             </dict>
             <dict>
                 <key>name</key>
                 <string>TM_COMMENT_START_2</string>
                 <key>value</key>
                 <string>/*</string>
             </dict>
             <dict>
                 <key>name</key>
                 <string>TM_COMMENT_END_2</string>
                 <key>value</key>
                 <string>*/</string>
             </dict>
         </array>
     </dict>
     <key>uuid</key>
     <string>FBA964F9-2013-44D1-A5FD-AE8AB3FF8954</string>
 </dict>
 </plist>

添加注释文件后,就可以为C#代码添加注释了。

配置五可以添加关键字高亮

 编程语言的关键字在ST2中是高亮显示的,对于ST2我们需要自己定义一下关键字,例如:virtual,var等,这时我们需要修改Packages文件夹中的C#文件夹的C#.tmLanguage文件,修改后文件的内容如下:

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
     <key>fileTypes</key>
     <array>
         <string>cs</string>
     </array>
     <key>foldingStartMarker</key>
     <string>^\s*/\*|^(?![^{]*?//|[^{]*?/\*(?!.*?\*/.*?\{)).*?\{\s*($|//|/\*(?!.*?\*/.*\S))</string>
     <key>foldingStopMarker</key>
     <string>^\s*\*/|^\s*\}</string>
     <key>keyEquivalent</key>
     <string>^~C</string>
     <key>name</key>
     <string>C#</string>
     <key>patterns</key>
     <array>
         <dict>
             <key>begin</key>
             <string>///</string>
             <key>captures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.comment.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>$\n?</string>
             <key>name</key>
             <string>comment.block.documentation.source.cs</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>begin</key>
                     <string>(&lt;/?)(?:([-_a-zA-Z0-9]+)((:)))?([-_a-zA-Z0-9:]+)</string>
                     <key>captures</key>
                     <dict>
                         <key>1</key>
                         <dict>
                             <key>name</key>
                             <string>punctuation.definition.tag.source.cs</string>
                         </dict>
                         <key>2</key>
                         <dict>
                             <key>name</key>
                             <string>entity.name.tag.namespace.source.cs</string>
                         </dict>
                         <key>3</key>
                         <dict>
                             <key>name</key>
                             <string>entity.name.tag.source.cs</string>
                         </dict>
                         <key>4</key>
                         <dict>
                             <key>name</key>
                             <string>punctuation.separator.namespace.source.cs</string>
                         </dict>
                         <key>5</key>
                         <dict>
                             <key>name</key>
                             <string>entity.name.tag.localname.source.cs</string>
                         </dict>
                     </dict>
                     <key>end</key>
                     <string>(/?&gt;)</string>
                     <key>name</key>
                     <string>keyword.other.documentation.source.cs</string>
                     <key>patterns</key>
                     <array>
                         <dict>
                             <key>captures</key>
                             <dict>
                                 <key>1</key>
                                 <dict>
                                     <key>name</key>
                                     <string>entity.other.attribute-name.namespace.source.cs</string>
                                 </dict>
                                 <key>2</key>
                                 <dict>
                                     <key>name</key>
                                     <string>entity.other.attribute-name.source.cs</string>
                                 </dict>
                                 <key>3</key>
                                 <dict>
                                     <key>name</key>
                                     <string>punctuation.separator.namespace.source.cs</string>
                                 </dict>
                                 <key>4</key>
                                 <dict>
                                     <key>name</key>
                                     <string>entity.other.attribute-name.localname.source.cs</string>
                                 </dict>
                             </dict>
                             <key>match</key>
                             <string> (?:([-_a-zA-Z0-9]+)((:)))?([_a-zA-Z-]+)=</string>
                         </dict>
                         <dict>
                             <key>include</key>
                             <string>#doubleQuotedString</string>
                         </dict>
                         <dict>
                             <key>include</key>
                             <string>#singleQuotedString</string>
                         </dict>
                     </array>
                 </dict>
             </array>
         </dict>
         <dict>
             <key>include</key>
             <string>#comments</string>
         </dict>
         <dict>
             <key>begin</key>
             <string>(?x)^\s*
 ((?:\b(?:new|public|protected|internal|private|abstract|sealed|static)\b\s)*)
 (class)\s+
 ([A-Za-z_]\w+)\b</string>
             <key>captures</key>
             <dict>
                 <key>1</key>
                 <dict>
                     <key>name</key>
                     <string>storage.modifier.source.cs</string>
                 </dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>storage.type.source.cs</string>
                 </dict>
                 <key>3</key>
                 <dict>
                     <key>name</key>
                     <string>entity.name.type.class.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>{</string>
             <key>name</key>
             <string>meta.definition.class.source.cs</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>include</key>
                     <string>#classInheritance</string>
                 </dict>
             </array>
         </dict>
         <!--
         Disabled because it causes some lines to be interpreted incorrectly, for example:
             else if (c == ')')
         --->
         <!--
         <dict>
             <key>begin</key>
             <string>(?x)^\s*                                                                                # start of line
 ((?:\b(?:new|public|protected|internal|private|static|virtual|sealed|override|abstract|extern)\b\s*)*)         # method-modifiers
 \b((?:\w+\.)*[A-Za-z_]\w*)\b\s*                                                                                  # type
 (operator)\s+                                                                                                  # operator overload
 ((?:\+|-|!|~|\+\+|--|true|false|\*|/|%|\&amp;|\||\^|&lt;&lt;|&gt;&gt;|==|!=|&lt;|&gt;|&lt;=|&gt;=)\s*)                                      # operator name
 (?=\()</string>
             <key>captures</key>
             <dict>
                 <key>1</key>
                 <dict>
                     <key>name</key>
                     <string>storage.modifier.source.cs</string>
                 </dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>storage.type.source.cs</string>
                 </dict>
                 <key>3</key>
                 <dict>
                     <key>name</key>
                     <string>storage.modifier.source.cs</string>
                 </dict>
                 <key>4</key>
                 <dict>
                     <key>name</key>
                     <string>entity.name.function.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>\)</string>
             <key>name</key>
             <string>meta.definition.operator.source.cs</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>include</key>
                     <string>#statementRemainder</string>
                 </dict>
             </array>
         </dict>
         <dict>
             <key>begin</key>
             <string>(?x)^\s*                                                                            # start of line
 ((?:\b(?:new|public|protected|internal|private|static|virtual|sealed|override|abstract|extern)\b\s*)*)     # method-modifiers
 \b((?:\w+\.)*[A-Za-z_]\w*)\b\s*                                                                              # type
 ([A-Za-z_]\w*)\s*                                                                                             # name
 (?=\()</string>
             <key>captures</key>
             <dict>
                 <key>1</key>
                 <dict>
                     <key>name</key>
                     <string>storage.modifier.source.cs</string>
                 </dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>storage.type.source.cs</string>
                 </dict>
                 <key>3</key>
                 <dict>
                     <key>name</key>
                     <string>entity.name.function.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>\)</string>
             <key>name</key>
             <string>meta.definition.method.source.cs</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>include</key>
                     <string>#statementRemainder</string>
                 </dict>
             </array>
         </dict>
         -->
         <dict>
             <key>match</key>
             <string>\b(true|false|null|this|base)\b</string>
             <key>name</key>
             <string>constant.language.source.cs</string>
         </dict>
         <dict>
             <key>match</key>
             <string>\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\b</string>
             <key>name</key>
             <string>constant.numeric.source.cs</string>
         </dict>
         <dict>
             <key>match</key>
             <string>\b(if|else|while|for|foreach|do|return|continue|break|switch|case|default|goto|throw|try|catch|finally|lock|yield)\b</string>
             <key>name</key>
             <string>keyword.control.source.cs</string>
         </dict>
         <dict>
             <key>match</key>
             <string>\b(new|is|checked|unchecked|typeof|sizeof|override|in|out|ref|readonly|params|stackalloc|as)\b</string>
             <key>name</key>
             <string>keyword.operator.source.cs</string>
         </dict>
         <dict>
             <key>match</key>
             <string>\b(event|delegate|explicit|implicit|in|set|get)\b</string>
             <key>name</key>
             <string>keyword.other.source.cs</string>
         </dict>
         <dict>
             <key>match</key>
             <string>\b(internal|public|protected|private|static|const|new|sealed|abstract|virtual|override|extern|unsafe|readonly|volatile|operator)\b</string>
             <key>name</key>
             <string>storage.modifier.source.cs</string>
         </dict>
         <dict>
             <key>include</key>
             <string>#doubleQuotedStringLiteral</string>
         </dict>
         <dict>
             <key>include</key>
             <string>#doubleQuotedString</string>
         </dict>
         <dict>
             <key>include</key>
             <string>#singleQuotedString</string>
         </dict>
         <dict>
             <key>captures</key>
             <dict>
                 <key>1</key>
                 <dict>
                     <key>name</key>
                     <string>keyword.other.using.source.cs</string>
                 </dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>entity.name.type.package.source.cs</string>
                 </dict>
             </dict>
             <key>match</key>
             <string>^\s*(using)\s+([^ ;]*);</string>
             <key>name</key>
             <string>meta.keyword.using.source.cs</string>
         </dict>
         <dict>
             <key>include</key>
             <string>#builtinTypes</string>
         </dict>
         <dict>
             <key>captures</key>
             <dict>
                 <key>1</key>
                 <dict>
                     <key>name</key>
                     <string>keyword.other.namespace.source.cs</string>
                 </dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>entity.name.type.namespace.source.cs</string>
                 </dict>
             </dict>
             <key>match</key>
             <string>^\s*(namespace)\s+([^ ]+)(?:\s*{)?$</string>
             <key>name</key>
             <string>meta.keyword.namespace.source.cs</string>
         </dict>
         <dict>
             <key>captures</key>
             <dict>
                 <key>2</key>
                 <dict>
                     <key>name</key>
                     <string>keyword.control.import.source.cs</string>
                 </dict>
             </dict>
             <key>match</key>
             <string>^(#)\s*(if|else|elif|endif|define|undef|warning|error|line|region|endregion)\b</string>
             <key>name</key>
             <string>meta.preprocessor.source.cs</string>
         </dict>
     </array>
     <key>repository</key>
     <dict>
         <key>builtinTypes</key>
         <dict>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>match</key>
                     <string>\b(bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|class|struct|enum|interface|var|from|where|select|group|into|orderby|join|let|ascending|descending|on|by)\b</string>
                     <key>name</key>
                     <string>storage.type.source.cs</string>
                 </dict>
             </array>
         </dict>
         <key>classInheritance</key>
         <dict>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>begin</key>
                     <string>:</string>
                     <key>end</key>
                     <string>(?={)</string>
                     <key>patterns</key>
                     <array>
                         <dict>
                             <key>captures</key>
                             <dict>
                                 <key>1</key>
                                 <dict>
                                     <key>name</key>
                                     <string>storage.type.source.cs</string>
                                 </dict>
                             </dict>
                             <key>match</key>
                             <string>\s*,?([A-Za-z_]\w*)\b</string>
                         </dict>
                     </array>
                 </dict>
             </array>
         </dict>
         <key>comments</key>
         <dict>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>begin</key>
                     <string>/\*</string>
                     <key>captures</key>
                     <dict>
                         <key>0</key>
                         <dict>
                             <key>name</key>
                             <string>punctuation.definition.comment.source.cs</string>
                         </dict>
                     </dict>
                     <key>end</key>
                     <string>\*/\n?</string>
                     <key>name</key>
                     <string>comment.block.source.cs</string>
                 </dict>
                 <dict>
                     <key>captures</key>
                     <dict>
                         <key>1</key>
                         <dict>
                             <key>name</key>
                             <string>punctuation.definition.comment.source.cs</string>
                         </dict>
                     </dict>
                     <key>match</key>
                     <string>(//).*$\n?</string>
                     <key>name</key>
                     <string>comment.line.double-slash.source.cs</string>
                 </dict>
             </array>
         </dict>
         <key>doubleQuotedString</key>
         <dict>
             <key>begin</key>
             <string>"</string>
             <key>beginCaptures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.string.begin.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>"</string>
             <key>endCaptures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.string.end.source.cs</string>
                 </dict>
             </dict>
             <key>name</key>
             <string>string.quoted.double.source.cs</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>match</key>
                     <string>\\.</string>
                     <key>name</key>
                     <string>constant.character.escape.source.cs</string>
                 </dict>
             </array>
         </dict>
         <key>doubleQuotedStringLiteral</key>
         <dict>
             <key>captures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.string.begin.source.cs</string>
                 </dict>
             </dict>
             <key>match</key>
             <string>@"([^"]|"")*"</string>
             <key>name</key>
             <string>string.quoted.double.literal.source.cs</string>
         </dict>
         <key>singleQuotedString</key>
         <dict>
             <key>begin</key>
             <string>'</string>
             <key>beginCaptures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.string.begin.source.cs</string>
                 </dict>
             </dict>
             <key>end</key>
             <string>'</string>
             <key>endCaptures</key>
             <dict>
                 <key>0</key>
                 <dict>
                     <key>name</key>
                     <string>punctuation.definition.string.end.source.cs</string>
                 </dict>
             </dict>
             <key>name</key>
             <string>string.quoted.single.xml</string>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>match</key>
                     <string>\\.</string>
                     <key>name</key>
                     <string>constant.character.escape.source.cs</string>
                 </dict>
             </array>
         </dict>
         <key>statementRemainder</key>
         <dict>
             <key>patterns</key>
             <array>
                 <dict>
                     <key>begin</key>
                     <string>\(</string>
                     <key>end</key>
                     <string>(?=\))</string>
                     <key>name</key>
                     <string>meta.definition.param-list.source.cs</string>
                     <key>patterns</key>
                     <array>
                         <dict>
                             <key>include</key>
                             <string>#builtinTypes</string>
                         </dict>
                     </array>
                 </dict>
             </array>
         </dict>
     </dict>
     <key>scopeName</key>
     <string>source.cs</string>
     <key>uuid</key>
     <string>1BA75B32-707C-11D9-A928-000D93589AF6</string>
 </dict>
 </plist>

配置六可以添加代码片段

 对于一些常用的代码片段,我们不需要每次都手动输入一遍,可以将它们配置问代码片段,减少手动代码输入量,效果类似于Visual Studio的智能提示,如下: 例如输入fore时,会出现foreach的提示:

然后Enter后就可以看到

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
        foreach (var item in )
        {
            
        }
        Console.ReadLine();
    }

总结

 对了,还可以修改字体大小哦

感觉很好用哦。

配置文件下载:C#.zip (将所有文件复制Packages文件夹下的C#文件夹即可,配置文件包括常用的代码片段,注释配置,和关键字的定义。)

这是我现在使用的Submile Text所有文件,下载解压http://url.cn/UXdqo4。然后设置环境变量,并设置一下配置三就可以了,当然有很多功能还有待自己摸索和开发哦

参考博客http://www.cnblogs.com/IPrograming/archive/2013/05/02/ST2_CSharpConfig.html

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏散尽浮华

Centos6.X 下安装并使用VNC的操作记录

VNC是一个的"远程桌面"工具。,通常用于“图形界面”的方式登录服务器,可视化操作。废话不多说了,操作记录如下: 1)安装桌面环境 [root@vm01 ~]#...

41470
来自专栏Python、Flask、Django

Mac自带磁盘跑分情况(买的移动固态到了)

13520
来自专栏月色的自留地

新麦装机问题汇

15130
来自专栏禅林阆苑

利用NextCloud配置私有云 【原创】

利用NextCloud配置私有云 Write By CS逍遥剑仙 我的主页: www.csxiaoyao.com GitHub: github...

2.7K80
来自专栏杂烩

kafka-eagle1.1.9安装 原

源码地址https://github.com/smartloli/kafka-eagle

13910
来自专栏派森公园

docker的reap问题

在使用docker容器的时候,应该了解“PID1僵尸进程reap”问题。如果使用的时候不加注意,可能会导致出现一些意想不到的问题。

17330
来自专栏张高兴的博客

张高兴的 UWP 开发笔记:应用内启动应用 (UWP Launch UWP)

37690
来自专栏北京马哥教育

chkconfig命令详细介绍

命令介绍: chkconfig命令用来更新、查询、修改不同运行级上的系统服务。比如安装了httpd服务,并且把启动的脚本放在了/etc/rc.d/init.d目...

43480
来自专栏恰童鞋骚年

.NET Core微服务之基于Consul实现服务治理(续)

上一篇发布之后,很多人点赞和评论,不胜惶恐,这一篇把上一篇没有弄到的东西补一下,也算是给各位前来询问的朋友的一些回复吧。

19450
来自专栏圣杰的专栏

IdentityServer4 知多少

现在的应用开发层出不穷,基于浏览器的网页应用,基于微信的公众号、小程序,基于IOS、Android的App,基于Windows系统的桌面应用和UWP应用等等,这...

34320

扫码关注云+社区

领取腾讯云代金券