Code snippet system in Visual studio is awkward and outdated comparing to PyCharm or VS code, but sometimes you just so get used to something so you keep using it.
This time I will tell about how to add custom python code snippets to VS 2017. Same on older versions I believe.
First you need to open already existing snippet. Open snippet manager, copy path from folder and open snipept in VS or any other editor.
In my case this path is
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Snippets\1033\Python
Open any snippet from this path. Not it might opened as XML or as a snippet. Both way are ok since *.snippet is actually XML file.
If this opened as snippet then you’ll get something like this:
Everything is simple here. You paste code, add variables in replacements tab and save is somewhere.
If this opened as XML this:
Here you need to type your own code. Basically place it between
<Code Language="Python"><![CDATA[ YOUR CODE ]]>
<![CDATA[class $name$(QMainWindow, ui.class_ui):
if __name__ == '__main__':
app = QApplication()
w = $name$()
Newt save your file with snippet extension somewhere. I do it on my google drive, so all my snippets are synchronized between machines.
Then open VS code snippet manager and click Add button to add new path to search snippets. Choose your folder.
Now your snippets must be visible from VS. To add them start typing shortcut you’ve set up earlier and then hit enter and then TAB. Start typing variable name then hit enter to apply changes to code. Click to see animation.