Why this module comes after Module 13

If you're thinking "shouldn't text editors come before the command line?" — you're right. Module 6 already gave you a quick nano cheat sheet with the four buttons you needed straight away. This module is the proper deep dive: how to use nano well, how to escape vim alive, how to bend .bashrc to your will. If Module 6 felt a bit thin, this is the part that finishes the job.

TYPE html> Linux editors and shell environment: nano, vim, .bashrc, tmux — win2linux

Module 11 · Editors & Environment 45 min

Every Windows user hits the same two walls on Linux: "I can't edit this file" and "this terminal feels weird." This module sorts both. You'll learn to edit files without flinching, get out of vim without panic, and set up your terminal so it actually feels like yours.

By the end of this module, you will:

  • Edit configuration files using nano without assistance
  • Exit vim without panicking using the survival sequence (Esc :q!)
  • Customise the terminal environment by editing ~/.bashrc
  • Create command aliases that reduce repetitive typing
  • Read, set, and export environment variables (PATH, EDITOR, LANG)
  • Use tmux to keep terminals running across SSH disconnects and split your screen

Why text editors matter more than you'd think

On Windows you double-click a file and a window opens. On Linux — especially on a server, where there's no desktop to click on — you have to use a text editor inside the terminal. Every settings file in /etc, every script you write, every scheduled job: all of it goes through a text editor. You really do have to know at least one.

The three editors you'll bump into

nano — the friendly one. It shows you all its buttons at the bottom of the screen. Start with this one. vim — the powerful one. It's everywhere, but it's tricky if you don't know it. You only need enough to not get stuck inside it. VS Code — yes, the same one you use on Windows. Use it for everyday editing whenever you've got a real desktop.

Your setup: .bashrc and shortcuts

Windows hides its settings inside the Registry and the Environment Variables window. Linux just uses plain text files. The main one is ~/.bashrc — it runs by itself every time you open a terminal. (The cousin file, ~/.bash_profile, runs when you log in.) Editing ~/.bashrc is how you make the terminal feel like yours: pick your prompt's colours, set shortcuts, change defaults.

nano — start with this one

nano puts all its shortcuts right at the bottom of the screen, so you can always see what does what. The little ^ symbol means Ctrl. So ^X just means "press Ctrl and X together". There's nothing to memorise past the handful of basics below.

nano — open, edit, save, exit
user@ubuntu:~$ nano myfile.txt
# nano opens. You see the file contents (empty if new).
# Type anything you want. Arrow keys move cursor.
# Bottom of screen shows shortcuts:
# ^G Help ^O Write Out ^X Exit
# ^K Cut ^U Paste ^W Search

user@ubuntu:~$ nano /etc/hosts
# Ctrl+W to search: type "localhost", Enter to find
# Ctrl+O to save: press Enter to confirm filename
# Ctrl+X to exit (it asks to save if unsaved changes)
nano filename.txt
Windows: Notepad filename.txt
Opens the file so you can edit it. If the file doesn't exist yet, nano makes it for you.
Click to copy
Ctrl+O → Enter
Windows: Ctrl+S
Saves the file. (nano calls saving "Write Out" — same thing.) When it asks for the filename, just press Enter to keep the one you already had.
Click to copy
Ctrl+X
Windows: Alt+F4 (Notepad)
Quits nano. If you have unsaved changes, it asks Y or N — that's it. No tricky exit dance.
Click to copy
Ctrl+W
Windows: Ctrl+F
Search inside the file. Type the word you're looking for, press Enter. Press Ctrl+W again to jump to the next match.
Click to copy
Ctrl+K
Windows: Ctrl+X (cut line)
Cuts the whole line your cursor is on. Then move somewhere else and press Ctrl+U to paste it back in.
Click to copy
Ctrl+G
Windows: F1 (Help)
Shows the full help screen, which reminds you of every shortcut. Press Ctrl+X to get out of the help and back to your file.
Click to copy

vim — the five commands that get you out alive

Why vim catches people out

vim has two modes — two completely different states it can be in. When you first open vim, you're in Normal mode, which is for moving around and giving commands. To actually type letters into the file, you have to switch to Insert mode first. If you don't know that, you open vim, start typing, and the screen does weird stuff because vim is reading each letter as a command. Every beginner gets caught by this. The fix: press i first, then type normally.

vim — the five commands that save you
user@ubuntu:~$ vim myfile.txt
# You are now in NORMAL mode. The cursor sits on the file.
# Do NOT type yet — you will not see what you expect.

i → Enter INSERT mode. Now type normally.
Esc → Return to NORMAL mode (always safe to press).
:w → Write (save) the file. Type :w Enter.
:q → Quit. Only works if no unsaved changes.
:wq → Write and quit (save and exit). The one you want.
:q! → Quit WITHOUT saving. Force-quit. No changes kept.

# The full escape sequence if you are stuck and panicking:
Press Esc, then type :q! and press Enter
# This exits vim immediately without saving anything.

The vim escape rule

If you ever get lost in vim and don't know what's going on: press Esc (that always puts you back into Normal mode), then type :q! and press Enter. You're out. Nothing is saved, nothing is broken — you can just start again. Memorise that one sequence and vim can never trap you.

Making the terminal yours — .bashrc

Every single time you open a terminal, Linux quietly runs a file called ~/.bashrc first. It's a list of commands that set up your terminal — your prompt colours, your shortcuts, your defaults. Think of it as a personal settings file just for the terminal. Open it with nano ~/.bashrc, make your changes, save, then type source ~/.bashrc to load them right away (no need to close and reopen the terminal).

~/.bashrc — your terminal home
user@ubuntu:~$ nano ~/.bashrc
# Scroll to the bottom of the file and add your customisations:

# ── ALIASES (shortcuts) ──────────────────────────────────────
alias ll='ls -la'
# Now typing "ll" runs "ls -la" (like dir in Windows)
alias ..='cd ..'
# Typing ".." goes up one directory
alias update='sudo apt update && sudo apt upgrade -y'
# Typing "update" runs both apt commands at once
alias myip='curl -s ifconfig.me'
# Typing "myip" shows your public IP address

# ── ENVIRONMENT VARIABLES ────────────────────────────────────
export EDITOR=nano
# Sets nano as the default editor (stops git from opening vim)
export HISTSIZE=5000
# Keep 5000 commands in history (default is 500)

# ── CUSTOM PROMPT (PS1) ──────────────────────────────────────
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# Green username@hostname, blue path. Looks professional.

user@ubuntu:~$ source ~/.bashrc
# Reloads .bashrc. New aliases and settings take effect now.
# No need to open a new terminal.
On WindowsOn LinuxWhat's different
NotepadnanoFriendly — the shortcuts are right there at the bottom
Notepad++ (for power users)vim or geditvim in the terminal, gedit if you've got a desktop
VS Code on WindowsVS Code on LinuxExactly the same app. Install with Snap or a .deb file.
Environment Variables (in System Properties)~/.bashrc or /etc/environmentAdd a line like export KEY=value
Adding to your PATHexport PATH="$HOME/bin:$PATH" in .bashrcAdds your folder to the front of the existing list
Doskey macros (those one-line shortcuts)aliase.g. alias ll='ls -la' in .bashrc
Windows Terminal profiles~/.bashrc or ~/.zshrcWhere you set everything about your shell
Programs that run at login (Task Scheduler)~/.bash_profile or a systemd user unit.bash_profile runs once when you sign in

Handy extras to drop into .bashrc

Practical .bashrc additions for Windows migrants
# Better history — don't store duplicates, save timestamps
export HISTCONTROL=ignoredups:erasedups
export HISTTIMEFORMAT="%d/%m/%y %T "

# Coloured ls output (like Windows Explorer colour-coding)
alias ls='ls --color=auto'
alias grep='grep --color=auto'

# Quick navigation shortcuts
alias docs='cd ~/Documents'
alias dl='cd ~/Downloads'
alias logs='cd /var/log && ls'

# Safety aliases (no accidental overwrites)
alias cp='cp -i'
# cp -i asks "overwrite?" before replacing files
alias mv='mv -i'
alias rm='rm -i'
# rm -i asks "remove?" before deleting. Your safety net.

# Show disk usage, sorted by size
alias duh='du -h --max-depth=1 | sort -hr'
# Typing "duh" in any directory shows what's using space

One line that stops vim ambushing you

Add this single line to the bottom of your ~/.bashrc: export EDITOR=nano. From then on, every Linux tool that needs you to "open the editor" — git when you write a commit message, crontab -e, visudo and a few others — will open nano instead of vim. Once you're comfortable with vim later, swap the line. For now, this is what keeps you out of trouble.

Installing VS Code on Ubuntu

If you already use VS Code on Windows, you'll be happy: it's exactly the same app on Linux. All your extensions, all your keyboard shortcuts, all your habits — they all just work. Install it once and use it for almost everything; keep nano for quick edits in the terminal.

Installing VS Code on Ubuntu
# Option 1: Snap (easiest, auto-updates)
user@ubuntu:~$ sudo snap install code --classic

# Option 2: Microsoft .deb package (recommended for enterprise)
user@ubuntu:~$ wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
user@ubuntu:~$ sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
user@ubuntu:~$ echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list
user@ubuntu:~$ sudo apt update && sudo apt install code

# Open VS Code from terminal (opens in current directory)
user@ubuntu:~$ code .
# VS Code opens, file tree shows current directory.
# All your Windows extensions will prompt to install on Linux.

Environment variables — the terminal's labelled drawers

An environment variable is just a labelled value the terminal can read. Think of them as drawers with names on them — EDITOR, PATH, LANG — and inside each drawer is the answer to one question. They decide where the terminal looks for programs, which editor opens for git commit, which language Linux talks to you in. The three you'll change again and again are PATH, EDITOR and LANG.

Name What it controls Check it / set it
PATHThe list of folders the terminal searches when you type a command. ls works because /bin is on the list.See it: echo $PATH. Add a folder: export PATH="$HOME/bin:$PATH"
EDITORWhich editor opens when a tool needs you to type something (git, crontab, visudo).See it: echo $EDITOR. Set it: put export EDITOR=nano in ~/.bashrc
LANGLinux's language. Changes the language of messages, the date format, even how things sort.See it: echo $LANG. Examples: en_GB.UTF-8, fr_FR.UTF-8
HOMEThe path to your home folder. When you type cd by itself, this is where you go.See it: echo $HOME. (Don't change it — Linux sets it for you.)
PS1What your prompt looks like (the "user@host:~$" bit before you type). Change it to whatever you like.export PS1='\u@\h \w $ '
env, export, and PATH in practice
# See every environment variable currently set
user@ubuntu:~$ env | sort

# Set a variable for THIS shell session only (lost on close)
user@ubuntu:~$ MYVAR="hello"

# export it so child processes (programs you launch) see it too
user@ubuntu:~$ export MYVAR="hello"

# Make it permanent — append the export line to ~/.bashrc
user@ubuntu:~$ echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
user@ubuntu:~$ source ~/.bashrc # reload without opening a new terminal

# Find out where a command actually lives
user@ubuntu:~$ which python3
/usr/bin/python3

The classic "I just installed it but it says command not found" usually means the program is sitting in a folder like ~/.local/bin/foo, but that folder isn't on your PATH list — so the terminal doesn't know to look there. Fix: add export PATH="$HOME/.local/bin:$PATH" to ~/.bashrc, run source ~/.bashrc, and the command starts working. Saves a lot of head-scratching.

tmux — terminal sessions that don't die when you disconnect

tmux is a tool that does two clever things. First, it splits one terminal window into several panes so you can watch a few things at once. Second — and this is the magical bit — it keeps your terminal sessions running even after you close the window or get disconnected. Start a job over SSH, lose your Wi-Fi, log back in later, ask tmux to bring the session back, and the job is still chugging along right where you left it.

Install it with sudo apt install tmux. The way tmux works is: you press Ctrl+b first (called the "prefix"), let go, then press the next key. So Ctrl+b then d means: hold Ctrl+b, release, then tap d.

What you want to do How to do it
Start a new session called "work"tmux new -s work
Step out of the session (it keeps running)Ctrl+b then d
See which sessions you havetmux ls
Come back to a sessiontmux attach -t work
Split the current pane top-and-bottomCtrl+b then "
Split the current pane side-by-sideCtrl+b then %
Jump between panesCtrl+b then an arrow key
Close the current paneType exit (or press Ctrl+d)
Open a new tab inside the sessionCtrl+b then c — switch tabs with Ctrl+b then a number

The classic moment tmux saves you: you SSH into a server somewhere, run tmux new -s build, start a long backup or build, press Ctrl+b then d to step out, and log off for the night. Tomorrow you SSH back in, type tmux attach -t build, and there it is — the job's finished, the output is still on screen, and nothing was lost when your Wi-Fi dropped.