Editing Files in the Terminal¶
When you're logged into Unity, there's no graphical text editor: No VS Code window you can click into, no Notepad. If you need to edit a file, fix a typo in a job script, update a config file, or jot down a quick note, you need a terminal-based editor.
Two editors are available everywhere: nano and vi (or its improved variant, vim). They take completely different approaches, and both are worth knowing.
| nano | vi / vim | |
|---|---|---|
| Learning curve | Gentle: controls shown on screen | Steep: modal editing, nothing on screen |
| Best for | Quick edits, beginners | Power users, complex edits |
| Available on | Nearly all Linux systems | Every Linux system, always |
| Mouse support | Sometimes | Rarely (depends on config) |
While vi is the more powerful editor, we recommend to start with nano for quick edits. Learn enough vi to escape it when you accidentally end up inside it. That will happen inevitably because many tools use vi as their default text editor (e.g., git).
nano¶
nano is the friendliest terminal editor. When you open a file, the controls are printed at the bottom of the screen. You don't have to memorize anything to get started.
Opening a file¶
1. If a file of that name exists, nano will open it. 2. If there is no existing file under that name, nano will create a new one.The screen looks like this:

The ^ symbol means Ctrl. So ^X means Ctrl+X.
Essential nano controls¶
| Keys | Action |
|---|---|
| Ctrl+O then Enter | Save the file ("Write Out") |
| Ctrl+X | Exit nano (prompts to save if unsaved changes) |
| Ctrl+W | Search for text |
| Ctrl+K | Cut the current line |
| Ctrl+U | Paste the cut line |
| Ctrl+G | Open help |
| Arrow keys | Move the cursor |
A typical nano session¶
- Open the file:
nano job_script.sh - Use the arrow keys to navigate to the line you want to change
- Make your edit
- Press Ctrl+O then Enter to save
- Press Ctrl+X to exit
That's it. nano is intentionally simple.
Searching in nano
Press Ctrl+W, type a search term, and press Enter. Press Ctrl+W again to find the next match. Press Ctrl+C to cancel the search.
vi and vim¶
vi is the oldest and most universally available terminal editor. vim ("Vi IMproved") is the modern version and what you almost always get when you type vi on a modern system. On Unity, vi opens vim.
vi is powerful but has a reputation for being confusing. This is largely because it's modal: The same keys do different things depending on what mode you're in. This trips up almost everyone the first time and there are many memes about the alleged difficulty of exiting vi (seriously, google it).
The two essential modes¶
vi has multiple modes, but two cover nearly everything you need:
| Mode | What it does | How to enter it |
|---|---|---|
| Normal mode | Navigate, delete, copy, paste | Press Esc |
| Insert mode | Type text | Press I |
When you first open vi, you're in normal mode. Typing letters won't insert text; they're commands. You must press I before you can type.
This is the source of most vi confusion: people open vi, try to type, and end up executing a cascade of commands instead. When in doubt, press Esc to get back to normal mode.
Opening a file¶
Surviving vi: the minimum you need¶
Step 1 — Enter insert mode:
Press I to start typing. You'll see -- INSERT -- at the bottom of the screen.
Step 2 — Make your edit.
Step 3 — Return to normal mode:
Press Esc.
Step 4 — Save and quit:
Type :wq then press Enter. (w = write, q = quit)
Step 4 (alternative) — Quit without saving:
Type :q! then press Enter. The ! forces the quit without saving.
Stuck in vi?
Press Esc (possibly several times), then type :q! and press Enter. This exits without saving any changes. It's not elegant, but it works.
Normal mode: navigation and editing¶
Once you're comfortable with insert mode and saving, normal mode becomes genuinely useful. These commands work in normal mode (after pressing Esc):
Navigation:
| Key | Action |
|---|---|
| H / L | Move left / right |
| J / K | Move down / up |
| Arrow keys | Also work for movement |
0 | Go to beginning of line |
$ | Go to end of line |
gg | Go to top of file |
G | Go to bottom of file |
:42 then Enter | Jump to line 42 |
Editing:
| Key | Action |
|---|---|
| I | Enter insert mode before cursor |
| A | Enter insert mode after cursor |
| O | Open a new line below and enter insert mode |
| X | Delete character under cursor |
dd | Delete (cut) the current line |
yy | Yank (copy) the current line |
| P | Paste after cursor |
| U | Undo |
| Ctrl+R | Redo |
Searching:
| Key | Action |
|---|---|
/pattern then Enter | Search forward |
?pattern then Enter | Search backward |
| N | Next match |
| Shift+N | Previous match |
Saving and quitting (always from normal mode):
| Command | Action |
|---|---|
:w | Save (write) without quitting |
:wq or ZZ | Save and quit |
:q | Quit (only if no unsaved changes) |
:q! | Quit without saving (discard changes) |
Why learn vi at all?
vi is guaranteed to be present on every Linux system. That even includes minimal container images, embedded systems, and remote servers where nothing else is installed. If you're deep inside a container or on an emergency recovery shell, vi may be your only option.
Choosing between them¶
Use nano when:
- You're making a quick fix to a job script
- You're new to terminal editors
- You don't need anything fancy
Use vi when:
- nano isn't available (rare, but happens in containers)
- You're already in vi and need to make a change
- You want to invest in learning an editor that will serve you anywhere
For longer editing sessions, like writing analysis scripts, building complex pipelines, consider using VS Code with the Remote-SSH extension to edit files on Unity from your laptop with a full graphical interface. See Connecting to Unity for details.
Quick Reference¶
nano¶
| Keys | Action |
|---|---|
| Ctrl+O → Enter | Save |
| Ctrl+X | Exit |
| Ctrl+W | Search |
| Ctrl+K | Cut line |
| Ctrl+U | Paste line |
vi / vim¶
| Keys | Action |
|---|---|
| I | Enter insert mode |
| Esc | Return to normal mode |
:wq → Enter | Save and quit |
:q! → Enter | Quit without saving |
dd | Delete line |
yy / P | Copy / paste line |
/pattern → Enter | Search |
| U | Undo |
What's Next¶
- Linux: Permissions, Pipes & the Environment: File permissions, pipes, and shell configuration
- Storage on Unity: Understand where your files live and how to manage them