2021年05月05日
Due to popular demand (?) at my lab in ETH Zürich, I will describe the tips & tricks for when I set up programming environements on my computer. Feel free to steal the ones you find useful. Suggestions and ideas are always welcome!
28.04.2023: updated with better sectioning, update descriptions, and add the screen
command.
29.10.2021: updated with new entries like GitHub Copilot (this is a potential game-changer for coders) and Ubuntu-specific UI customizations.
zsh
shellThe command shell is what runs on your terminal to let you interact with the computer. For example, ls
, cd
, etc are all bash commands.
By the end of this section, you will have
cmake
- it suggests commands I typed in the past that match the current input)Zsh is an extended version of the bash shell. Change from bash to zsh (for macOS zsh is already the default shell), for Ubuntu…
Next, install Oh My Zsh, which among other things lets you use plugins and themes on the zsh shell. Installation can be done by
After installing ohmyzsh, install zsh-autosuggestions for the autocomplete feature.
Edit ~/.zshrc
and add zsh-autosuggestions
to the corresponding line for plugins. For example, if the git
plugin is already enabled as is the default case, it would look like
plugins=(git zsh-autosuggestions)
And now you have autocomplete features in the terminal! When suggestions start showing up, press ↑ / ↓ to cycle through past commands that match the current input, → to choose the command currently being shown transparently, or alt + f to autocomplete word by word.
For the theme, I prefer powerlevel10k, though this is just a personal preference.
This works like a simpler version of the zsh-autosuggestions
plugin, but it is available by default in both bash and zsh, and also many other text input interfaces like the Python interpreter.
Just press ctrl-r, and start typing to start searching your past commands. If you press ctrl-r again it will keep cycling through old commands that match the string that is being currently typed. When the command that you want shows up, just press enter to execute that line. For example, the screenshot below shows what happens in the Python interpreter when I do ctrl-r to go into reverse-i-search mode and start typing import n
- it already suggest the line import numpy as np
.
This is the same for bash and zsh, and probably any other terminal emulator. use alt-f to go forward, and alt-b to go back one word at a time. alt-d to delete the word in front of the cursor. This is also the emacs keybind for the same movements.
# Ubuntu
sudo apt install terminator
# macOS
brew install terminator
and use it as your terminal emulator (it is installed as an app, so just launch it like any other app). Use ctrl-shift-o and ctrl-shift-e to split panes, and alt - [arrow key] to move between panes.
screen
For example if you want to run a long computation on a remote server. Use the screen
command to enter a new screen, start running your program, and then ctrl-a + d to detach from the screen. You can then exit the terminal, and the program will keep running in the background. When you want to check on the program, just ssh back into the server and use screen -r
to reattach to the screen.
This gives you AI-powered suggestions while you code, which you can choose to use by pressing tab. I really cannot stress how much more efficient this makes you at writing code, especially for writing menial code that are similar across different projects (e.g. initial setup of OpenCV windows). It works for many programming languages, even plain text; you can even try to have a simple conversation with it. Sometimes it’s creepy how accurately it can guess my intensions when I code. However, there are just as many instances where it suggests completely off-the-mark code. Use with a healthy dose of caution.
It’s still in technical preview, so you’ll have to enroll in it on their website.
If you are opening a project with a CMakeLists.txt
file in the top directory, you can set up VSCode to compile your programs from GUI.
Install the cmake extension, ctrl-shift_p (the shortcut for VSCode commands) and select “CMake: Configure”. Then select compiler, probably gcc **.**.**
.
Select the CMake icon in the sidebar, and it should have a list of all the executables and libraries in the project. Right-click and you can “build”, “run”, “debug”, etc.
Press ctrl-shift-p to enter the VSCode command terminal, and enable settings sync. It’s so much easier to use multiple computers when you can use your editor configured exactly the same way on all your devices.
Use the Vim extension for VSCode. It will let you do a lot of things, like moving the cursor or switching between files, without ever having to touch the mouse. If you will code anything over 100 lines, I recommend picking up these commands, as once you master them it will definitely let you code much faster and efficiently.
However there is somewhat of a steep learning curve to be able to use Vim, so you could run the vimtutor
command for a tutorial, or try out this pretty cool RPG-style vim tutorial online.
Or use Emacs, that’s totally cool as well.
jj
to enter insert modeI recommend setting it up so you can switch to insert mode with jj
instead of the ESC key which can be hard to press.
"vim.insertModeKeyBindings": [
{
"before": ["j", "j"]
"after": ["<Esc>"]
}
],
inoremap <silent> jj <ESC>
The GNOME Extension Bing Wallpaper will refresh your Ubuntu desktop with Bing’s picture of the day, it’s pretty nice
This site has basically every single macOS wallpaper that there has ever been.
□