Quite often, in my day-to-day workflow, I want to wrap up some code section in a well-known code snippet. I hate these moments. Usually, you want to cut and paste some code, and after that formatting goes wrong and all of that 😱. So…

I would like to share with you extension for vscode that I wrote for personal use. (marketplace.visualstudio.com/surround-with-csharp) The goal of this extension is to provide the capability to wrap up selected text in a C# code snippet.

This extension supports different concepts to trigger functionally to surround your code.

Source code: https://github.com/NikiforovAll/surround-with-csharp


You can just simply hit CTRL + SPACE and if you have some code selected, you will get completion items that you can choose from by using arrow keys:



If your favorite command-pallette. You can invoke command “C#: Surround With” (or CTRL+SHIFT+S, CTRL+SHIFT+S) and you will be prompted for a code snippet.


Customize Keybindings

Here is a list of keybindings provided by extension for quicker access to commands to use a particular snippet. You can assign your own keybindings if you want to.

Snippet Keybinding
surround.with.namespace ctrl+shift+S N
surround.with.for ctrl+shift+S F
surround.with.foreach ctrl+shift+S ctrl+F
surround.with.do ctrl+shift+S D
surround.with.while ctrl+shift+S W
surround.with.if ctrl+shift+S I
surround.with.else ctrl+shift+S E
surround.with.try ctrl+shift+S T
surround.with.tryf ctrl+shift+S ctrl+T
surround.with.lock ctrl+shift+S L

Some commands are not bound at all. So if you are “I want to wrap all my code in regions” kind of guy, you can go to “Keyboard Shortcuts” and find all subcommands. Usually, the name starts with “surround.with”.

Hope you find this useful, have fun! 🎉

Oleksii Nikiforov

Jibber-jabbering about programming and IT.