Learn › RHCSA (EX200) › Exam Orientation + Essential Tools
vim - a hands-on Linux lab on a real virtual machine.
Drive vim to exam fluency: the three modes, i/a/o and Esc, :wq versus :q!, dd/yy/p/u, gg/G, search with /pattern and n, and the global substitute :%s/old/new/g. Serves the EX200 objective "create and edit text files."
It is exam day. A task tells you to add a line to /etc/hosts, or fix a typo in /etc/fstab, or drop a rule into a sudoers file. There is no mouse-driven editor, no internet, no notes. You open the file, and a screen full of text stares back with a cursor that will not move the way you expect. If you cannot drive it, you cannot finish the task, and the RHCSA is nothing but tasks like this.
That editor is vim, and it is the one editor guaranteed to be installed on every RHEL 10 machine. nano might be there, might not. vim always is. This lesson serves the exam objective Create and edit text files, and it gets you to the level the exam actually demands: open a config file, change it correctly, save it, get out, and move on to the next task without losing a second.
The black boxes below are a practice terminal: a safe sandbox that checks the one command each step teaches. vim itself is a full-screen interactive program, so it has no single line of output to show. Instead these reps do one of two things. Some run a normal command whose result IS stable, like the version banner. The rest CREATE a file the exact way the keystrokes would, then cat it so you see the real finished content. The keystrokes you would press inside vim are spelled out in the words and the hint. On the real machine at the end of the module, you drive vim live.
vim is a text editor that runs entirely in the terminal. It is the successor to vi, which has shipped with Unix since 1976, and the name means vi improved. The one idea that makes vim feel alien at first is modes. Most editors are always ready to type. vim is not. It has three modes, and a keystroke means something different in each.
Normal mode is where you land when you open a file. Here every key is a command: keys move the cursor, delete lines, copy, paste. You cannot type text yet. Insert mode is the one where letters you press actually appear in the file. Command-line mode is where you type a colon command like save or quit. The whole trick is knowing which mode you are in and how to move between them.
If you ever feel lost, press Esc. It always brings you back to Normal mode, no matter where you are. From Normal mode you can always find your way to save, quit, or start typing again. Pressing Esc when you are already in Normal mode does no harm, so press it freely.
The obvious question is why anyone would build an editor you cannot just type into. The answer is age and speed. vi was written for terminals with no arrow keys and no menus, where reaching for a modifier key was slow. So the letter keys themselves became the commands. Once your hands know them, you edit without ever leaving the home row, which is exactly why the tool survived fifty years and why Red Hat still puts it on every box.
For the exam you do not need to love it. You need a small, reliable set of moves that never fails you under pressure. That is what the next few reps build. First, prove vim is installed at all. Every program can report its own version, and vim --version prints a banner whose first line names the release. Ask for just that first line.
vim --version | head -1
prompt: student@servera:~$ answer: vim --version | head -1 output: VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Apr 08 2026 00:00:00) hint: Ask vim for its version, then keep only the first line. Pipe vim --version into head -1.
That banner is from the AlmaLinux 10.2 exam image, so the patch and compile date on your machine may read slightly differently. The part that matters is the same everywhere: VIM - Vi IMproved, version 9.x. If that line prints, vim is installed and ready.
Here is the core loop you will run on almost every exam task. You open a file, switch to Insert mode, type, switch back to Normal, and save-and-quit. In vim you would run vim /tmp/hosts-note.txt, press i to enter Insert mode, type your line, press Esc to return to Normal mode, then type :wq and Enter. That last command is the workhorse. :w writes (saves) the file, :q quits, and :wq does both in one go.
The practice terminal cannot run a full-screen editor, so you will produce the exact same result the keystrokes would, using printf to write the file, then read it back to prove the content landed. Create the file and show it:
printf '192.168.1.10 servera\n' > /tmp/hosts-note.txt; cat /tmp/hosts-note.txt
prompt: student@servera:~$ answer: printf '192.168.1.10 servera\n' > /tmp/hosts-note.txt; cat /tmp/hosts-note.txt output: 192.168.1.10 servera hint: Use printf to send one line into /tmp/hosts-note.txt with >, then cat the file. Remember the \n at the end of the printf string.
That one line in the file is exactly what i, typing, Esc, :wq would have produced inside vim. Fix the four commands in your head now, because they never change: i starts typing, Esc stops typing, :w saves, :q quits, and :wq saves and quits together. There is one more way to save and quit that costs fewer keystrokes: from Normal mode, press ZZ (capital Z, twice, no colon). It is identical to :wq. Many engineers use ZZ all day.
This is the single most important pair in the whole lesson, and the exam punishes getting it wrong. :wq saves your changes and quits. :q! throws your changes away and quits. The ! means force: quit even though there are unsaved edits, and lose them on purpose. You reach for :q! when you have made a mess in a critical file and want to walk out as if you never touched it.
Picture the danger. You spend three minutes editing /etc/fstab, then quit with :q! out of habit. Every change is gone and the grader sees nothing. Or the reverse: you scrambled a config while exploring, save it with :wq, and now the file is broken. Saying the right one out loud before you press Enter is a real exam habit. Let us prove the two outcomes with files you can read. First, the SAVE path, a file that keeps its edit:
printf 'edited and saved\n' > /tmp/wq-demo.txt; cat /tmp/wq-demo.txt
prompt: student@servera:~$ answer: printf 'edited and saved\n' > /tmp/wq-demo.txt; cat /tmp/wq-demo.txt output: edited and saved hint: Write the line edited and saved into /tmp/wq-demo.txt with printf and >, then cat it. This is what :wq leaves behind.
:q! is the opposite outcome: the file on disk keeps whatever it had BEFORE you started, because your edits were discarded. Use :wq when the edit is good and :q! only when you want to abandon your changes. If you are ever unsure whether you saved, :wq is the safe choice: it writes and leaves.
Editing config files is mostly moving, deleting, and duplicating whole lines, and vim has three Normal-mode commands for exactly that. dd deletes (cuts) the current line. yy yanks (copies) the current line. p pastes what you last cut or copied on the line below the cursor. To jump around while you do this: gg goes to the first line of the file, G goes to the last line, and u undoes your last change if you slip.
Say you want to copy the first line to the bottom of a file. In vim you would press gg to reach the top, yy to yank that line, G to reach the bottom, then p to paste it below. The finished file has the first line repeated at the end. Reproduce that result and read it back:
printf 'alpha\nbravo\ncharlie\nalpha\n' > /tmp/lines.txt; cat /tmp/lines.txt
prompt: student@servera:~$ answer: printf 'alpha\nbravo\ncharlie\nalpha\n' > /tmp/lines.txt; cat /tmp/lines.txt output: alpha bravo charlie alpha hint: Build the four lines alpha, bravo, charlie, alpha with one printf and \n between each, then cat the file. The repeated alpha at the end is the yy then p result.
The alpha at the top and the alpha at the bottom are the yank-and-paste in action: yy copied it, p dropped the copy in. Had you pressed dd on line two instead, bravo would be gone and sitting in the paste buffer, ready for p to place it elsewhere. And if any of that went wrong, u walks it back one step at a time. These four, dd, yy, p, and u, plus gg and G to travel, cover the bulk of real config edits.
The last power move is finding and changing text without hunting by hand. In Normal mode, type / followed by a word and Enter to search forward for it. The cursor jumps to the first match, and pressing n jumps to the next match, again and again. That alone saves you in a long file. But the exam favorite is the substitute command, run from command-line mode: :%s/old/new/g. Read it in parts. The % means every line in the file. The s means substitute. The old is the text to find and new is the replacement. The trailing g means every occurrence on each line, not just the first.
So :%s/dev/prod/g changes every dev to prod across the whole file. Reproduce that finished result: start from a file full of dev, and show it after the substitution turned them into prod.
printf 'server-prod-1\nserver-prod-2\n' > /tmp/sub.txt; cat /tmp/sub.txt
prompt: student@servera:~$ answer: printf 'server-prod-1\nserver-prod-2\n' > /tmp/sub.txt; cat /tmp/sub.txt output: server-prod-1 server-prod-2 hint: Write the two already-substituted lines server-prod-1 and server-prod-2 into /tmp/sub.txt with printf, then cat it. This is what the file looks like after :%s/dev/prod/g runs.
One more Normal-mode convenience: :set number turns on line numbers down the left edge, which makes long config files far easier to navigate and matches error messages that name a line. It is a display setting only, it does not change the file, and it lasts until you quit. Type :set number and Enter whenever a file feels hard to read.
Scaffolding off. No command shown. You have every piece you need.
A colleague left /tmp/motd.txt with the placeholder word HOSTNAME on it, and it must instead read servera. Picture the vim session. You would open the file, run :%s/HOSTNAME/servera/g to swap the word everywhere, then save and quit with :wq. Here in the practice terminal, produce the finished file the way that session would leave it. Write the corrected line into /tmp/motd.txt, then read it back to confirm the swap.
prompt: student@servera:~$ answer: printf 'Welcome to servera\n' > /tmp/motd.txt; cat /tmp/motd.txt output: Welcome to servera hint: The finished line reads Welcome to servera. Use printf with > to write it into /tmp/motd.txt, then cat the file to prove the substitution and save landed.
That is the whole exam loop in one move: you found the wrong word, replaced every copy of it with :%s/old/new/g, and left with :wq so the change stuck. The file on disk now reads Welcome to servera, which is exactly what a grader would check. You recalled the substitute form and the save command from memory, with nothing shown, and that recall is what the real machine will ask of you.
You earned this cheat sheet. Every entry is something you just used or narrated:
The two to burn into memory: :wq saves, :q! discards. Say the right one before you press Enter and you will never lose an exam edit.
Two traps to name now. First, if random letters scatter across the screen while you try to type, you are in Normal mode, not Insert: press Esc, then i, and try again. Second, if :q refuses to quit with a message about unsaved changes, you did edit something: use :wq to keep it or :q! to drop it. Neither is an error, both are vim protecting your work.
The practice terminal has shown you the shape of every vim move: the three modes, entering Insert with i, a, o and leaving with Esc, saving and quitting with :wq versus discarding with :q!, line surgery with dd, yy, p, u, travel with gg and G, search with / and n, and the global substitute :%s/old/new/g. You recalled the last one with nothing on screen.
The essential-tools module ends on one real RHEL 10 machine, the essential-tools capstone mission, and that is where you drive vim live for the first time. A full machine boots for you, with real config files to open and edit. The mission hands you objectives drawn from exactly what you practiced across this module, and it shows no commands: you read the objective, recall the keystrokes, and make the file correct. That recall under a real editor is what turns vim from alien into automatic.
Finish the other essential-tools lessons, then go edit a real file for yourself.
Practice vim Essentials in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.