File Editing on the Omega
In this Guide, there will be many experiments that make use of Python and Shell scripts. To get these scripts to run, we store the program code on the Omega as a file.
On the Omega, there’s only one text editor installed by default -
vim. It’s different from more familiar editors in how it works, so we’ll cover the basics super quickly before we move on to making cool things faster!
Creating or Opening a File
To work with a file, simply call
vim <filename>. It will work if you do
vi <filename> as well.
If the file already exists, it will open it in vim. If it doesn’t, it will open an empty temporary file with the given name.
The temporary file won’t be permanent until you save it!
If you type things immediately when vim starts, nothing will come out. So how do we get text in?
i to get into ‘insert mode’, now we can start entering text!
The controls of insert mode should be quite familiar if you’ve used notepad before. The keys will insert characters, the arrow keys provide nagivation, and
home/end/pgup/pgdn will behave accordingly.
Vim is based on different modes. Entering characters and pasting with
ctrl-shift-v will only work in insert mode.
Vim begins in normal mode, where all keystrokes are interpreted as commands. So all the text you want to paste will be interpreted as commands, causing lots of unpredicatble changes to the file.
If mistakes were made, what can we do?
Undo and Redo
Undo is a normal mode function, hit
ESC and press
u to undo the last bit of changes made. To redo hit
ctrl-r in normal mode.
The reason we hit
ESC first is to return to normal mode. So instead of inserting
u, vim will undo the last changes we made.
Once the code is fixed, it’s time to save.
ESC to enter normal mode, then
:w and enter.
: calls the ‘command line’ of vim, where we can run vim’s less often used functions. The command we give it is
w which stands for ‘write to file’. Since
: works like a command like, we have to
enter to send our command to it.
The more commonly used commands in vim are related to navigating, copy/pasting, and editing chunks of text - like
Now that we’ve saved, we’ll have to exit vim to test the script.
Quitting and Saving changes
The quitting process is very similar to saving - return to normal mode with
: to enter the
q command to quit vim.
Vim also has the ability to accept multiple commands and execute them in order. So we can save and quit by typing
Quitting without Saving Changes
Forcing vim to quit can be done by adding
! to the end of the
Normally when trying to exit vim with unsaved changes, vim will deny the attempt as a safe measure. But quitting without saving is also useful to revert really big changes.
More on Vi
There’s a lot more than meets the eye with vim. It’s actually a very powerful editor under the hood and can be installed in all major operating systems. If you want to learn how to make the most out of it, Open Vim has a fantastic tutorial that can get you started.