Insert GUIDs directly into Visual Studio Code

Heath Stewart

Let me preface this by stating I love Visual Studio Code! While I think its big, older brother Visual Studio is great for large solutions or even small projects where project files are managed automatically by the IDE, Code work great for small, loose projects and is very fast. I still use Vim for a lot of quick edits in a console (I spend a lot of time in powershell.exe even when using Visual Studio for development) but Code has quickly been filling that niche for source code in various languages.

But when frequently having to author GUIDs for something-or-other, my routine of generating GUIDs in different formats, copying, and pasting them into source is burdensome. After seeing many of the cool first- and third-party extensions available for Code and how concise the API is, I wrote my own extension to actually insert GUIDs into the current document.

It was also a fun opportunity to delve deeper into managing modules through NPM and working with TypeScript.

Installing the extension is easy:

  1. Open the command palette: Ctrl+Shift+P or Cmd+Shift+P on Mac
  2. Type: Install Extension
  3. Type: Insert GUID
  4. Press Enter or click the download button to install

And with a recent update, using it is even easier:

  1. Type: Ctrl+Shift+[ which actually equates to Ctrl+{ or Cmd+{ on Mac
  2. Press the number corresponding to the format you want
  3. Press Enter

Multi-line formats will put the cursor on the next line while single-line formats – like those you might put in XML attributes – do not. This felt like a reasonable improvement over the separate Create GUID utility that ships with VS, as was inserting directly into the document instead of copying to the clipboard.

Feel free to check out the source and leave feedback for improvements.


Discussion is closed.

Feedback usabilla icon