简体   繁体   中英

Visual studio 2015 C# Shorten command

How can I make a text/command to shorten a command like: Console.Write(""); so that if I just write cw then it would automatically write Console.Write(""); ?

As stated in the comments, cw is actually a preset code snippet for Console.WriteLine() that can be expanded by pressing Tab. You can also create custom code snippets .

But you do specifically ask about expanding cw on its own without pressing Tab as needed for Code Snippets. I was actually just recently looking to do something similar for interpolated strings and haven't come across anything within VS.

If you want to automatically expand cw as code or want to customize hotkeys, I've found simple AutoHotKey (AHK) scripts like the ones below to be useful for that. You can can do a lot more with AHK as well, like keep key presses in memory. It can really lend flexible scripting like customization to your IDE. Notice the #IfWinActive, ahk_exe devenv.exe line makes the script specific to VS.

Make cw an AutoExpanding HotString (Tab not required)

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

Make cw a Tab expanded HotString (like VS code snippets)

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

Hotkey for Ctrl+[

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM