Visual Studio 2015 C#缩短命令

时间:2017-10-03 14:06:13

标签: c# visual-studio

如何创建一个文本/命令来缩短像Console.Write("");这样的命令,这样如果我只写cw那么它会自动写Console.Write("");

1 个答案:

答案 0 :(得分:0)

正如评论中所述,cw实际上是Console.WriteLine()的预设代码段,可以通过按Tab扩展。您还可以创建custom code snippets

但是你特别要求自己扩展cw,而不需要根据代码片段的需要按Tab键。实际上我最近只想做something similar for interpolated strings并且在VS内没有遇到任何事情。

如果您想自动展开cw作为代码或想要自定义热键,我发现下面的简单AutoHotKey (AHK)脚本对此有用。您也可以使用AHK做更多事情,比如在内存中保持按键。它可以真正为您的IDE提供灵活的脚本,如自定义。请注意#IfWinActive, ahk_exe devenv.exe行使脚本特定于VS.

cw成为AutoExpanding HotString(不需要Tab)

#SingleInstance force
#IfWinActive, ahk_exe devenv.exe
:*:cw::Console.WriteLine(

使cw Tab扩展HotString(如VS代码段)

#SingleInstance force
#IfWinActive, ahk_exe devenv.exe
#Hotstring EndChars `t
::cw::Console.WriteLine(

Ctrl + [

的热键
#SingleInstance force
#IfWinActive, ahk_exe devenv.exe
^[::
SendInput,Console.WriteLine(