CMU 15-112: Fundamentals of Programming and Computer Science
Class Notes: Getting Started with Go & VSCode
- If you haven't already, install and run VSCode from here
- Install Go from here
- Click on the 'Extensions' tab on the left toolbar
- Type 'Go' into the search bar and install the extension by Microsoft named simply 'Go'
- Type 'run in terminal' into the search bar and install the Run in Terminal extension
- Type 'multi-command' into the search bar and install the multi-command extension if you have not done so previously
- Click 'cmd + shift + p' (Mac) or 'ctrl + shift + p' (Windows) to open the 'Command Palette'.
- Type in 'Settings' then click on 'Preferences: Open Settings (JSON)'
- 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": ".*"}}, ] }, ], }
- Reopen the Command Palette. This time, type in 'Keyboard Shortcuts' and click on 'Preferences: Open Keyboard Shortcuts (JSON)'
- 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"}, ]
-
Make VSCode the default editor on your computer.
Mac:- Open Finder
- Right click on a Go file
- Choose 'Get Info'
- Set 'Open With' to VSCode
- select 'Change All'
- Open File Explorer
- Right click on a Go file
- Choose 'Open With' > 'Choose Default Program'
- Set 'Opens With' to VSCode
- Restart VSCode, and now you're ready to Go (pun absolutely intended)! Press cmd+g or ctrl+g to run your code.