与notepad 相似的mysql编译器_比NotePad++更好的文本代码(C#)编辑器Sublime Text

本文介绍了如何将Sublime Text配置成一个强大的C#代码编辑器,包括添加C#编译器路径到环境变量,配置编译系统以编译和运行C#代码,设置注释快捷键,关键字高亮,以及代码片段,使其成为Notepad++的优秀替代品。
摘要由CSDN通过智能技术生成

前言

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

配置一调用C#编译器

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

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

配置二新建编译器选项

打开Submile Text

0b9622ec7d03887a39cb79c1719f58ac.png

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

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

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

0e2c21777172ad4e15012c857bfeb338.png

测试编译代码

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

usingSystem;usingSystem.Linq;classProgram

{static void Main(string[] args)

{

Console.WriteLine("Hello World");

Console.ReadLine();

}

}

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

07a0b981ab0a72767f43b268bac84d37.png

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

配置三能让代码运行起来

其实很简单,就是在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一下刚刚写的简单的代码吧

ff4523f5c5669bb87120679355753339.png

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

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

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.pngView Code

View Code<?xml version="1.0" encoding="UTF-8"?>

name

Comments

scope

source.cs

settings

shellVariables

name

TM_COMMENT_START

value

//

name

TM_COMMENT_START_2

value

/*

name

TM_COMMENT_END_2

value

*/

uuid

FBA964F9-2013-44D1-A5FD-AE8AB3FF8954

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

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

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

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.pngView Code

fileTypes

cs

foldingStartMarker

^\s*/\*|^(?![^{]*?//|[^{]*?/\*(?!.*?\*/.*?\{)).*?\{\s*($|//|/\*(?!.*?\*/.*\S))

foldingStopMarker

^\s*\*/|^\s*\}

keyEquivalent

^~C

name

C#

patterns

begin

///

captures

0

name

punctuation.definition.comment.source.cs

end

$\n?

name

comment.block.documentation.source.cs

patterns

begin

(</?)(?:([-_a-zA-Z0-9]+)((:)))?([-_a-zA-Z0-9:]+)

captures

1

name

punctuation.definition.tag.source.cs

2

name

entity.name.tag.namespace.source.cs

3

name

entity.name.tag.source.cs

4

name

punctuation.separator.namespace.source.cs

5

name

entity.name.tag.localname.source.cs

end

(/?>)

name

keyword.other.documentation.source.cs

patterns

captures

1

name

entity.other.attribute-name.namespace.source.cs

2

name

entity.other.attribute-name.source.cs

3

name

punctuation.separator.namespace.source.cs

4

name

entity.other.attribute-name.localname.source.cs

match

(?:([-_a-zA-Z0-9]+)((:)))?([_a-zA-Z-]+)=

include

#doubleQuotedString

include

#singleQuotedString

include

#comments

begin

(?x)^\s*((?:\b(?:new|public|protected|internal|private|abstract|sealed|static)\b\s)*)

(class)\s+([A-Za-z_]\w+)\b

captures

1

name

storage.modifier.source.cs

2

name

storage.type.source.cs

3

name

entity.name.type.class.source.cs

end

{

name

meta.definition.class.source.cs

patterns

include

#classInheritance

match

\b(true|false|null|this|base)\b

name

constant.language.source.cs

match

\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

name

constant.numeric.source.cs

match

\b(if|else|while|for|foreach|do|return|continue|break|switch|case|default|goto|throw|try|catch|finally|lock|yield)\b

name

keyword.control.source.cs

match

\b(new|is|checked|unchecked|typeof|sizeof|override|in|out|ref|readonly|params|stackalloc|as)\b

name

keyword.operator.source.cs

match

\b(event|delegate|explicit|implicit|in|set|get)\b

name

keyword.other.source.cs

match

\b(internal|public|protected|private|static|const|new|sealed|abstract|virtual|override|extern|unsafe|readonly|volatile|operator)\b

name

storage.modifier.source.cs

include

#doubleQuotedStringLiteral

include

#doubleQuotedString

include

#singleQuotedString

captures

1

name

keyword.other.using.source.cs

2

name

entity.name.type.package.source.cs

match

^\s*(using)\s+([^ ;]*);

name

meta.keyword.using.source.cs

include

#builtinTypes

captures

1

name

keyword.other.namespace.source.cs

2

name

entity.name.type.namespace.source.cs

match

^\s*(namespace)\s+([^ ]+)(?:\s*{)?$

name

meta.keyword.namespace.source.cs

captures

2

name

keyword.control.import.source.cs

match

^(#)\s*(if|else|elif|endif|define|undef|warning|error|line|region|endregion)\b

name

meta.preprocessor.source.cs

repository

builtinTypes

patterns

match

\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

name

storage.type.source.cs

classInheritance

patterns

begin

:

end

(?={)

patterns

captures

1

name

storage.type.source.cs

match

\s*,?([A-Za-z_]\w*)\b

comments

patterns

begin

/\*

captures

0

name

punctuation.definition.comment.source.cs

end

\*/\n?

name

comment.block.source.cs

captures

1

name

punctuation.definition.comment.source.cs

match

(//).*$\n?

name

comment.line.double-slash.source.cs

doubleQuotedString

begin

"

beginCaptures

0

name

punctuation.definition.string.begin.source.cs

end

"

endCaptures

0

name

punctuation.definition.string.end.source.cs

name

string.quoted.double.source.cs

patterns

match

\\.

name

constant.character.escape.source.cs

doubleQuotedStringLiteral

captures

0

name

punctuation.definition.string.begin.source.cs

match

@"([^"]|"")*"

name

string.quoted.double.literal.source.cs

singleQuotedString

begin

'

beginCaptures

0

name

punctuation.definition.string.begin.source.cs

end

'

endCaptures

0

name

punctuation.definition.string.end.source.cs

name

string.quoted.single.xml

patterns

match

\\.

name

constant.character.escape.source.cs

statementRemainder

patterns

begin

\(

end

(?=\))

name

meta.definition.param-list.source.cs

patterns

include

#builtinTypes

scopeName

source.cs

uuid

1BA75B32-707C-11D9-A928-000D93589AF6

配置六可以添加代码片段

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

例如输入fore时,会出现foreach的提示:

3c2e66daf1e2b1ed0e0da77bb2a1dc42.png然后Enter后就可以看到

static void Main(string[] args)

{

Console.WriteLine("Hello World");foreach (var item in)

{

}

Console.ReadLine();

}

总结

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

2384fac343df44f29921be858cf68d25.png

6bfd5c84e6007a04f7a79ced2a3d8b05.png

感觉很好用哦。

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值