15 min to read
Five VIM Commands You'll Use 500 Times a Week
From "How Do I Quit This Thing?" to Confidently Editing Files on Remote Servers
Picture this: You SSH into your lab’s HPC cluster at 11 PM because your pipeline crashed. You need to change one parameter in a configuration file. You type vim config.yaml, the file opens, and suddenly you’re frozen. Keys do random things. You can’t type. You can’t exit. In a moment of panic, you close your entire terminal window.
This scenario has happened to every bioinformatician at least once. Today, we fix that forever.
Creating Our Practice File
Before we start, let’s create a realistic file to work with—a simple pipeline configuration that you might actually encounter:
vim pipeline_config.txt
VIM opens. Don’t panic—we’re about to learn exactly what to do. For now, press i (you’ll understand why in a moment), then type or paste this configuration:
# RNA-seq Pipeline Configuration
threads=8
memory=16
reference=/data/genomes/hg38.fa
output=/scratch/results/
fastq_dir=/data/raw/
quality_cutoff=20
Now press the ESC key, then type :wq and press ENTER. Congratulations—you just created and saved a file in VIM. Now let’s understand what just happened and learn to do it deliberately.
The Foundation: Understanding Where You Are
VIM has different modes, but you only need to understand two right now:
Normal Mode - This is where VIM starts. Keys are commands, not text. This is where you navigate, delete, and execute operations. The bottom-left of your screen is blank or shows position information.
Insert Mode - This is where you type text like any other editor. The bottom-left shows -- INSERT --.
The most important key in VIM: ESC always returns you to Normal Mode. Confused? Press ESC. Stuck? Press ESC. Weird things happening? Press ESC. This is your reset button. Press it as many times as you need—it’s safe.
Command 1: Opening Files (Starting VIM)
From any terminal, opening a file is straightforward:
vim filename.txt
If the file exists, VIM opens it. If not, VIM will create it when you save. Let’s open the config file we just created:
vim pipeline_config.txt
The file appears in your terminal. VIM is in Normal Mode, waiting for commands. Your cursor blinks on the first character. Now what?
Command 2: Moving Around (Navigation)
You can use arrow keys to move around—there’s absolutely no shame in this when you’re starting. But VIM has something better: the hjkl keys that sit right under your fingers on the home row.
h - moves left
j - moves down
k - moves up
l - moves right
Why these keys? They’re positioned where your right hand naturally rests when typing. No reaching for arrow keys, no moving your hands, no breaking your flow.
Try this right now: With pipeline_config.txt open, use these keys to move around:
- Press
jrepeatedly to move down through the lines - Press
kto move back up - Press
lto move right across a line - Press
hto move left
Your cursor moves with each press. Hold a key down to move continuously—try holding j to scroll down through the file quickly.
Real-world usage: You have a 200-line sample sheet and need to check if sample_173 has the correct path. You hold down j to scroll quickly through entries until you spot it. Your hands never leave the keyboard.
For now, use whichever navigation method feels comfortable—arrows or hjkl. As you use VIM more, hjkl will start feeling natural without you consciously deciding to switch.
Command 3: Inserting Text (Actually Typing)
Here’s where VIM confuses newcomers: you open a file and press keys, but nothing appears. That’s because you’re in Normal Mode where keys are commands. To actually type text, you need to enter Insert Mode.
The i Key: Insert Before Cursor
Navigate to where you want to add text, then press i. The bottom-left shows -- INSERT --. Now type normally—every key produces a character just like any other editor.
When you’re done typing, press ESC to return to Normal Mode.
Example: Let’s add a comment to our config file. Open it:
vim pipeline_config.txt
Navigate to the line with threads=8. Press i. You’re in Insert Mode. Type:
# Core processing settings
Press ENTER to create a new line (still in Insert Mode). Press ESC to return to Normal Mode. You just inserted text before your cursor position.
The A Key: Append to End of Line
Press A (capital A) and VIM:
- Jumps to the end of the current line
- Enters Insert Mode
This is incredibly useful for editing command lines or file paths.
Example: Our config has output=/scratch/results/ but we need to add a subdirectory. Navigate to that line, then press A. Your cursor jumps to the end, and you’re in Insert Mode. Type:
rnaseq/batch1/
Press ESC. Done. The line now reads output=/scratch/results/rnaseq/batch1/.
The pattern you’ll use constantly:
- Navigate to the right line (using
j,k, arrows) - Press
ito insert at cursor orAto append at line end - Type your text
- Press
ESCto return to Normal Mode
Command 4: Deleting Characters (The x Command)
In Normal Mode, pressing x deletes the character under your cursor. Simple, direct, powerful.
Example: Our config has a typo. The line reads:
quality_cutoff=200
But we need quality_cutoff=20. Navigate your cursor to the third 0 in 200. Press x. The character disappears. Press it again if you need to delete more characters.
Common scenario: You have extra spaces in a file path:
fastq_dir=/data/raw//
Navigate to one of the extra slashes. Press x. It’s gone. Much faster than entering Insert Mode, using backspace, and exiting again.
Pro tip: Hold down x to delete multiple characters quickly when you need to clear several at once.
Command 5: The Commands That Matter Most (Saving and Exiting)
This is it—the knowledge that prevents you from ever being trapped in VIM again.
Save and Exit: :wq
When you’re done editing and want to save changes:
- Press
ESC(to ensure you’re in Normal Mode) - Type
:wq - Press
ENTER
You’ll see :wq appear at the bottom of the screen as you type. The : enters Command Mode, w means write (save), and q means quit.
Alternative: :x does the same thing (save and exit). Use whichever you remember easier.
Exit Without Saving: :q!
If you opened a file just to look or made changes you want to discard:
- Press
ESC - Type
:q! - Press
ENTER
The ! forces quit without saving. If you try :q and VIM says “No write since last change,” it’s warning you have unsaved edits. Use :q! to discard them or :wq to save them.
Just Save (Keep Editing): :w
Sometimes you want to save progress but keep working:
- Press
ESC - Type
:w - Press
ENTER
The file saves, but VIM stays open. This is essential when editing long scripts—save periodically so you don’t lose work if something goes wrong.
Example scenario: You’re updating a complex Snakemake workflow. Every few edits, you press ESC, type :w, press ENTER, and continue. If you make a mistake later, you can exit without saving (:q!) and you’ll only lose changes since your last save.
Your First Real Edit: Complete Workflow
Let’s put everything together with a task you’ll do constantly: updating pipeline parameters after a test run fails.
The Scenario
Your RNA-seq pipeline ran out of memory. You need to increase the memory allocation from 16 GB to 32 GB.
The Process
Open the file:
vim pipeline_config.txt
Navigate to the memory line:
- Use
jto move down until your cursor is on the linememory=16
Position your cursor on the number:
- Use
lto move right until you’re on the1in16
Delete the old value:
- Press
xto delete the1 - Press
xagain to delete the6
Insert the new value:
- Press
ito enter Insert Mode - Type
32 - Press
ESCto return to Normal Mode
Save and exit:
- Type
:wq - Press
ENTER
Done. File updated, ready to rerun your pipeline. Total time: 15 seconds.
Common Situations and Solutions
“I pressed random keys and weird things happened!”
Solution: Press ESC multiple times. If you made changes you don’t want, type :q! and press ENTER to exit without saving. Reopen the file and try again. This is completely safe and happens to everyone.
“I can’t type anything!”
Solution: You’re in Normal Mode. Press i to enter Insert Mode, then type.
“I pressed ESC but I’m still in Insert Mode!”
Solution: Press ESC again. Sometimes there’s terminal lag. If it still doesn’t work, try pressing Ctrl-C, which also returns to Normal Mode.
“VIM won’t let me exit!”
Solution: Press ESC, then type :q! and press ENTER. This exits without saving and works 100% of the time, no exceptions. If VIM shows a message about unsaved changes, that’s just a warning—the ! overrides it.
“The screen froze and VIM won’t respond!”
Solution: You probably accidentally pressed Ctrl-S, which freezes the terminal (this is a terminal feature, not VIM). Press Ctrl-Q to unfreeze. VIM will work normally again.
Practice Tasks
The best way to learn is to use VIM on real files immediately. Here are three quick exercises:
Task 1: Update a Number
Create a simple resource file:
vim resources.txt
Press i, type:
cores=4
ram=8
disk=100
Press ESC, type :wq, press ENTER.
Now edit it:
vim resources.txt
Change cores=4 to cores=16 using j or k to navigate, l to position cursor, x to delete, i to insert.
Save and exit with :wq.
Task 2: Add Line Comments
Create a script file:
vim analysis.sh
Press i, type:
#!/bin/bash
fastqc input.fastq
multiqc .
Press ESC, type :wq, press ENTER.
Reopen it and add a comment before the fastqc line:
vim analysis.sh
Navigate to the fastqc line, press i, type # Run quality control, press ENTER, press ESC.
Save with :wq.
Task 3: Fix a File Path
Create a config with a wrong path:
vim paths.txt
Press i, type:
data=/scratch/usre/project/
output=/results/
Press ESC, type :wq, press ENTER.
Fix the typo (usre → user):
vim paths.txt
Navigate to the e in usre, press x to delete it. Move cursor to after usr, press i, type e, press ESC.
Or delete the entire wrong part and retype: navigate to u in usre, press x four times, press i, type user, press ESC.
Save and exit: :wq.
Why These Five Commands Matter
Every file edit on a remote server follows this pattern:
- Open the file:
vim filename - Navigate to the right location:
hjklor arrows - Make changes:
iorAto insert,xto delete - Save and exit:
:wqor:q!
That’s it. These five commands handle 80% of your remote editing needs:
- Updating pipeline configurations
- Fixing paths in shell scripts
- Adjusting parameters after failed runs
- Adding samples to metadata files
- Correcting typos anywhere
You’re not fast yet—that comes with practice. But you’re functional. You can edit files on HPC clusters without fear. You know how to save your work and how to escape if things go wrong.
The Mental Model
Think of VIM like a two-state system:
Normal Mode is your control panel. You navigate and give commands. You spend most of your time here, moving around and deciding what to change.
Insert Mode is your typing state. You’re writing text. You enter, make your edits, and exit back to the control panel.
ESC is the transition back to control. Always. No matter what’s happening, ESC returns you to Normal Mode where you can figure out what to do next.
This model—command mode vs. insert mode—is what makes VIM different and ultimately more powerful than editors with a single mode. But you don’t need to appreciate that yet. For now, just remember: ESC brings you back to safety.
What You’ve Accomplished
You now have the core skills for VIM:
✓ Opening files on remote systems
✓ Moving around with hjkl or arrows
✓ Entering Insert Mode with i or A
✓ Actually typing and editing text
✓ Deleting characters with x
✓ Saving with :w or :wq
✓ Exiting without saving with :q!
✓ Understanding that ESC is your reset button
That’s enough to make you functional in VIM. You won’t be trapped. You won’t accidentally destroy files. You can make the edits you need on any remote system.
Building the Habit
For the next week, use VIM for every small edit you need to make on remote systems:
- Quick config changes
- Parameter updates
- Path corrections
- Adding comments
Don’t try to learn more commands yet. Just use these five consistently until they become automatic. Your fingers need to learn the pattern: navigate, insert, edit, exit. Once this feels natural—probably in 3-4 days of regular use—you’re ready for more advanced commands.
What’s Next
In the next post, we’ll level up your editing efficiency. You’ll learn how to:
- Delete entire words and lines (faster than holding
x) - Undo mistakes (because everyone makes them)
- Copy and paste text
- Search for specific text
- Replace text across the file
But for now, practice these fundamentals. The goal isn’t speed—it’s confidence. When you can open a file, make a change, and save without thinking about the commands, you’re ready to move forward.
Quick Reference
Pin this to your monitor for your first week:
STARTING:
vim filename - open/create file
NAVIGATION:
hjkl or arrows - move around
MODES:
i - insert before cursor
A - append at end of line
ESC - return to Normal Mode
EDITING:
x - delete character
SAVING/EXITING:
:w ENTER - save (keep editing)
:wq ENTER - save and exit
:q! ENTER - exit without saving
Remember: When in doubt, press ESC. You can never press it too many times.
You’re no longer trapped in VIM. You’re in control. In the next post, we’ll make you efficient.
Comments