github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/doc/templates/setup-editors.md (about) 1 # Recommended Editors for Writing Go Code 2 3 ## Visual Studio Code (VSCode) 4 5 For writing Go code (and other languages too) we highly recommend using the cross-platform editor **[Visual Studio Code](https://code.visualstudio.com/)**. 6 The teaching staff mainly use VSCode for Go programming. 7 8 ### Installing and Setting Up VSCode 9 10 Simply follow the instructions to install the program for your desired system. 11 12 For Go language support, use the **[Go extension](https://code.visualstudio.com/docs/languages/go)**, which gives you things such as intellisense (autocompletion, etc.) and linter (check code for errors). 13 You install the Go extension from the marketplace within VSCode. 14 15 Another useful VSCode extension is [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner), which allows to run code using a keyboard shortcut or right-clicking a file instead of using ``go run``. 16 Runs code by default in a read-only editor. 17 18 ### Developing in WSL with VSCode 19 20 If you are developing with WSL on Windows you can use VSCode for interacting with the WSL environment. 21 The VSCode documentation has [detailed instructions](https://code.visualstudio.com/docs/remote/wsl) for this use case. 22 23 ## GoLand 24 25 [GoLand](https://www.jetbrains.com/go/) is a proper IDE specially designed for the Go language. 26 This software is not free, but as a student you can create a [free student user account](https://www.jetbrains.com/community/education/?fromMenu), and thus use GoLand for free. 27 28 Some of GoLand's features include: 29 30 * Excellent refactoring support. 31 * On-the-fly error detection and suggestion for fixes. 32 * Navigation & Search. 33 * Run & Debug code without extra work. 34 35 ## Other Editors 36 37 If you prefer some other editor there exists Go support for many editors, such as Atom, Emacs, and vim. 38 The Go wiki maintains a [comprehensive list](https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins) of several IDEs and text editors that can be used for Go programming. 39 40 Whichever editor you choose, it is highly recommended that you configure it to use the [`goreturns`](https://github.com/sqs/goreturns) tool. 41 This will reformat your code to follow the Go style, and make sure that all the necessary import statements are inserted (so you don’t need to write the import statement when you start using a new package.) 42 The `goreturns` tool is compatible with most editors, but may require some configuration. 43 Using the Go plugin for VSCode should automatically configure `goreturns`. 44 45 Note that editors may also be able to run your code within the editor itself, but it may require some configuration. 46 However, using the go tool from the command line is often times preferred. 47 48 ### Basic vi/vim Usage 49 50 Sometimes it may be convenient to edit files using terminal-based editors, e.g. if you need to edit a file on a server via a SSH connection. 51 For these cases, we recommend vi or vim. 52 vi is typically preinstalled on most Unix systems, such as embedded systems (e.g. routers), set-top-boxes, etc. 53 vim (Vi IMproved) is a more powerful version of vi, which has many useful features and can be customized via configuration files and adding extensions. 54 vi/vim have a bit of learning curve compared to other editors, but many software developers find these to be very productive once you have gotten used to them. 55 If you intend to write most code in a remote environment or in a terminal, we recommend learning to use vim. 56 57 There are many detailed tutorials on vi/vim online, e.g. [here](http://www.washington.edu/computing/unix/vi.html). 58 Below is a short primer on vim. 59 60 To modify/write the file `file.go` with vim: 61 62 ```console 63 vim file.go 64 ``` 65 66 To exit vim without saving, use the command `:q!`. 67 To exit vim and save any changes, use the command: `:wq`. 68 To save any changes and continue editing, use the command: `:w`. 69 70 vim has two modes of operation. 71 When you open vim you start in *command mode*. 72 In command mode key presses are interpreted as shortcuts. 73 For example, 74 75 * `j` moves the cursor one line down, 76 * `k` moves it one line up, 77 * `h` moves one character to the left, and 78 * `l` moves one character to the right. 79 80 You could also use the arrow keys. 81 If you press `i` from command mode you enter the *insert mode*. 82 In this mode you can type, remove text with the `Backspace` and `Delete` keys, add new lines with the `Enter` key, and navigate with the arrow keys. 83 Press `Escape` to return to command mode from insert mode. 84 85 Other useful *command mode* features in vim: 86 87 * If you enter `:` you can enter some additional commands. For example: 88 * `:w` will save the file, 89 * `:q` will quit vim, 90 * `:wq` will save and quit vim, and 91 * `:q!` will discard modifications and quit vim. 92 * `:set nu` will enable line numbers. 93 * If you enter `/` you can search for some matching string. 94 E.g. `/word` will find the first match for `word` within the text (starting from the cursor position). 95 Go to the next match by pressing `n` and the previous match by pressing `N`. 96 * Some vim commands use "verbs" and "actions". 97 For example, by pressing `d` you start the action to delete something. 98 If you type `d3w` you will execute the action "delete 3 words". 99 If you enter the "verb" two times in a row it will generally affect the whole line, e.g. `dd` deletes the current line. 100 Note that special characters such as `-` are interpreted as a word, e.g. "a-b" counts as 3 words and can be deleted with `d3w`. 101 * Use the `y` (yank) "verb" to copy some text. 102 * `y3w` copies 3 words starting from the cursor. 103 * `yy` copies the whole line. 104 * Use `p` or `P` to paste. 105 * `p` pastes the text to the line below. 106 * `P` pastes the text above the current line. 107 * Use `o` or `O` to insert a new line. 108 * `o` inserts a new line below and enters insert mode. 109 * `O` inserts a new line above and enters insert mode. 110 * Use `u` to undo the last action. 111 This can be repeated to undo several actions. 112 * `b` moves the cursor one word back and `w` moves the cursor one word forward. 113 114 Other useful *insert mode* features in vim: 115 116 * If you have marked or copied some text, you can copy or paste it with `Ctrl+Shift+c` and `Ctrl+Shift+v`, respectively. 117 118 vimtutor is a tool which opens in vim and contains a beginner's guide to vim. 119 To enter vimtutor: 120 121 ```console 122 vimtutor 123 ``` 124 125 *NOTE: To exit vimtutor you have to use vim commands (either `:q` or `:q!`).*