CMU 15-112: Fundamentals of Programming and Computer Science
Class Notes: Getting Started with Go & VSCode



  1. If you haven't already, install and run VSCode from here

  2. Install Go from here

  3. Click on the 'Extensions' tab on the left toolbar


  4. Type 'Go' into the search bar and install the extension by Microsoft named simply 'Go'


  5. Type 'run in terminal' into the search bar and install the Run in Terminal extension


  6. Type 'multi-command' into the search bar and install the multi-command extension if you have not done so previously


  7. Click 'cmd + shift + p' (Mac) or 'ctrl + shift + p' (Windows) to open the 'Command Palette'.


  8. Type in 'Settings' then click on 'Preferences: Open Settings (JSON)'


  9. Paste these settings into the page that opens up (replacing the settings that are there) and hit save. Note that you may adjust the font sizes to match your personal preference.
    
    {
        "window.zoomLevel": 0,
        "editor.fontSize": 18,
        "terminal.integrated.fontSize": 18,
    
        "python.terminal.executeInFileDir": true,
        "python.terminal.launchArgs": ["-i"],
        "python.linting.pylintEnabled": false,
    
        "editor.quickSuggestions": false,
        "editor.acceptSuggestionOnEnter": "off",
        "editor.quickSuggestionsDelay": 10,
        "editor.wordBasedSuggestions": false,
        "editor.parameterHints.enabled": false,
        "editor.rulers": [80],
    
    
        "multiCommand.commands": [
            {
                "command": "multiCommand.runPythonREPL",
                "interval": 100,
                "sequence": [
                    "workbench.action.terminal.kill",
                    "python.execInTerminal",
                ]
            },
    
            {
                "command": "multiCommand.runGoREPL",
                "interval": 100,
                "sequence": [
                    "workbench.action.terminal.clear",
                    {"command": "runInTerminal.run", "args": {"cmd": "go run \"${file}\"", "match": ".*"}},
                ]
            },
    
        ],
    }
        


  10. Reopen the Command Palette. This time, type in 'Keyboard Shortcuts' and click on 'Preferences: Open Keyboard Shortcuts (JSON)'


  11. Paste these settings into the page that opens up (replacing the settings that are there) and hit save.
    
    [
       { "key": "cmd+b", "command": "multiCommand.runPythonREPL" },
       { "key": "ctrl+b", "command": "multiCommand.runPythonREPL"},
       { "key": "cmd+g", "command": "multiCommand.runGoREPL"},
       { "key": "ctrl+g", "command": "multiCommand.runGoREPL"},
    ]
        


  12. Make VSCode the default editor on your computer.
    Mac:
    1. Open Finder
    2. Right click on a Go file
    3. Choose 'Get Info'
    4. Set 'Open With' to VSCode
    5. select 'Change All'
    Windows:
    1. Open File Explorer
    2. Right click on a Go file
    3. Choose 'Open With' > 'Choose Default Program'
    4. Set 'Opens With' to VSCode


  13. Restart VSCode, and now you're ready to Go (pun absolutely intended)! Press cmd+g or ctrl+g to run your code.