Terminal Text Editors
Sooner or later you'll need to change a file while you're in a terminal: a config file on a server, a commit message, a .bashrc. A terminal text editor runs inside the terminal window, so it works over SSH where there is no graphical desktop. This lesson covers the editors you'll meet, how to survive in each, and how to hand off to a graphical editor such as VS Code.
| Editor | Where you find it | Difficulty | Good for |
|---|---|---|---|
| nano | most Linux distros, older macOS; installable everywhere | easy | quick edits, beginners |
| vim / vi | every Linux and macOS, every server | steep at first | fast editing once learned, always available |
Edit (edit) |
Windows 11 (new, 2025), installable with winget | easy | quick edits in a Windows terminal |
Notepad (notepad) |
every Windows | easy | opens a separate window |
VS Code (code) |
installed by you, all OSes | easy | real projects |
| emacs, micro, helix | installable | varies | enthusiasts |
nano: the friendly one
Start it with a file name: nano notes.txt (the file is created when you save). You type normally; the commands are listed at the bottom of the screen, where ^ means Ctrl:
GNU nano 7.2 notes.txt
Buy milk
Fix the build script█
^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute
^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify| Keys | Action |
|---|---|
Ctrl+O, then Enter |
save ("write out") |
Ctrl+X |
exit (asks to save if there are changes) |
Ctrl+W |
search |
Ctrl+K / Ctrl+U |
cut line / paste |
Alt+U |
undo |
On recent macOS versions nano is actually a link to the similar editor pico; brew install nano gets the real one.
vim: the one that's always there
Vim (and its ancestor vi) is installed on practically every Unix-like system, so it's worth knowing the basics even if you never love it. The confusing part is that vim has modes:
i, a, o Esc
NORMAL ───────────► INSERT ───────────► NORMAL
(keys are commands) (keys type text)
│
│ : Enter
└──────► COMMAND-LINE (:w :q :wq :q!)Vim starts in normal mode, where letters are commands, not text. The survival kit:
| Keys | Action |
|---|---|
i |
start inserting text before the cursor |
Esc |
back to normal mode (press it whenever in doubt) |
:w Enter |
save |
:q Enter |
quit (:q! quits without saving) |
:wq or ZZ |
save and quit |
/word Enter, n |
search, next match |
dd / p |
delete (cut) a line / paste it |
u / Ctrl+R |
undo / redo |
If you're ever stuck in vim (for example Git opened it for a commit message), press Esc, then type :q! and Enter. Run vimtutor for a 30-minute interactive lesson; it ships with vim.
Windows: Edit and Notepad
Windows 11 now includes Edit, a small modern terminal editor from Microsoft (edit notes.txt). It has menus, mouse support and familiar shortcuts: Ctrl+S save, Ctrl+Q quit, Ctrl+F find. If edit isn't found, install it with winget install Microsoft.Edit.
Notepad isn't a terminal editor, but starting it from the terminal is handy. The shell waits for nothing; Notepad opens in its own window:
C:\Users\ada>notepad todo.txtPS C:\Users\ada> notepad $PROFILEThe second example opens your PowerShell profile (see Aliases & Profiles). On macOS, open -e notes.txt opens a file in TextEdit, and open -t in the default text editor.
VS Code from the terminal: code .
When VS Code is installed, its code command opens files and folders from any shell. . means "the current folder", so the classic workflow is: cd into a project, then open it.
ada@ubuntu:~$ cd ~/projects/blog
ada@ubuntu:~/projects/blog$ code .ada@macbook ~ % code ~/.zshrcOn Windows and Linux the installer adds code to PATH. On macOS, open VS Code once, press Cmd+Shift+P and run Shell Command: Install 'code' command in PATH. Inside VS Code, Ctrl+` opens an integrated terminal in the same folder. code --wait file blocks until you close the tab, which is how tools such as Git can use it as their editor.
Which editor do tools open? EDITOR and VISUAL
Programs that need you to edit text (Git commit messages, crontab -e, sudo visudo) open the editor named in the EDITOR (or VISUAL) environment variable, falling back to vi or nano. Set it in your profile to choose:
# ~/.bashrc or ~/.zshrc
export EDITOR=nano
# or a graphical one that waits:
export EDITOR="code --wait"Git has its own setting, which works the same in every shell: git config --global core.editor "code --wait".
A script can read the variable and fall back to a default when it's empty:
unset EDITOR
echo "editor: ${EDITOR:-nano}"
EDITOR=vim
echo "editor: ${EDITOR:-nano}"editor: nano
editor: vim
Editing without an editor
Inside scripts, or for a quick one-off file, you don't open an editor at all: you write the text with redirection. Each shell has a way to write several lines at once:
cat > todo.txt <<'EOF'
- buy milk
- fix the build
EOF
echo "- call Bob" >> todo.txt
cat todo.txt- buy milk
- fix the build
- call Bob
@echo off
(
echo - buy milk
echo - fix the build
) > todo.txt
echo - call Bob>> todo.txt
type todo.txt- buy milk
- fix the build
- call Bob
@'
- buy milk
- fix the build
'@ | Set-Content todo.txt
Add-Content todo.txt '- call Bob'
Get-Content todo.txt- buy milk
- fix the build
- call Bob
For search-and-replace without an editor, see sed in Bash sed and -replace in PowerShell Strings.
Learn more: Editors on Linux, Creating Files & Folders, Redirection.
Test yourself
You're stuck in vim and want to leave without saving. What do you type?
Ctrl+XEscthen:q!exitCtrl+Ctwice
In nano, what does ^O in the help bar mean?
- Press Shift+O
- Press Ctrl+O (save)
- Type the letters ^ and O
- Open another file
What does code . do?
- Compiles the current folder
- Opens the current folder in VS Code
- Shows the source of the current command
- Lists code files