November 19, 2026
CTF Basics: Understanding Text Editors
Learn how to edit text files in the terminal, why vi is worth learning properly, and when a local editor like VS Code fits into the…

By Walter Moar
6 min read
Learn how to edit text files in the terminal, why vi is worth learning properly, and when a local editor like VS Code fits into the workflow.
This article covers text editors, which are used when the solution to a Capture The Flag (CTF) challenge involves changing the contents of files. The cat and xxd commands are great for viewing files, but when a script needs a fix, a config file needs a change, or a payload needs to be created line by line for an SSH session, then something else is needed. That something is a terminal text editor.
Since the editor will be run in the Linux terminal, this article won't make sense unless the terminal itself is understood. It's probably a good idea to first read "CTF Basics: Understanding the Linux Terminal".
Why cat Isn't Enough
The cat command is a quick way to display a file, and it can even create new files using output redirection:
waltermoar-academy@webshell:~$ cat > new_file.txt
This is some text
This is more text
CTRL-D
waltermoar-academy@webshell:~$ cat new_file.txt
This is some text
This is more text
waltermoar-academy@webshell:~$waltermoar-academy@webshell:~$ cat > new_file.txt
This is some text
This is more text
CTRL-D
waltermoar-academy@webshell:~$ cat new_file.txt
This is some text
This is more text
waltermoar-academy@webshell:~$This works for blocks of text typed once, but won't work if existing text needs to be changed. There's no way to make a change to line 1 without retyping everything again. An editor is needed as soon as "create a file" becomes "edit a file."
Note: if absolutely necessary, files could be "edited" with commands like
sedorawk, but that is going to extreme measures if there are editors available.
Two editors that come up constantly in CTF work are nano and vi (also called vim, for "vi improved"). A third editor, VS Code, is worth knowing about even though it isn't a terminal tool.
Both nano and vi are already installed in the CyLab WebShell, so there's no setup needed to try either one there. The WebShell is a great resource for many things, including practicing vi use on dummy data files.
nano: Friendly, But Not Guaranteed
nano is the friendlier editor. It behaves close to what most people expect from a text editor: arrow keys move the cursor, typing inserts text, and the commands are listed on screen the entire time.
waltermoar-academy@webshell:~$ nano script.pywaltermoar-academy@webshell:~$ nano script.pyThe bottom of the screen shows a row of shortcuts, each prefixed with ^ (meaning CTRL):
^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute
^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute
^X Exit ^R Read File ^\ Replace ^U Paste ^J JustifyCTRL-O saves the file (it asks to confirm the filename, just press Enter), and CTRL-X exits (it asks to save first, if there are unsaved changes). These two basics are really all that's needed to quickly edit a file, although nano obviously provides a lot more features like search, cut and paste, etc.
There is one catch with nano: it is not guaranteed to be installed! Plenty of minimal Linux environments, stripped-down Docker containers, and CTF challenge boxes don't include nano. This is because vi is already there, and a second editor is not needed. Only knowing nano means that eventually a vi-only machine will be encountered, and the toughest part of the challenge will be remembering how to use vi.
vi: (Almost) Always There
vi (which is actually almost always vim these days) is installed on most Linux and Unix servers, including ones stripped down to almost nothing. There might be super-minimal, or highly secure, CTF servers that don't provide an editor, but in those cases the challenge itself is probably the editing of a file without an editor like vi. The ubiquity of vi is the reason to learn it properly rather than treating it as a fallback: it's the one editor that can be assumed to be available.
It's worth using vi as the preferred editor, rather than only using it when nano isn't available. If vi is only used once every few months under pressure, it never becomes comfortable. However, if used as the default, even for small edits that don't need it, it becomes second nature. The learning curve for vi is real, but it's an essential skill. Learning vi is one of those "go slow to go fast" skills: it pays off the first time an unfamiliar CTF box, a locked-down container, or a production server (in the real world beyond CTF), turns out not to have any other editor.
vi Modes
The most important thing to understand about vi is that it has three modes, and typing does different things depending on which mode is active. Everyone used to a normal text editor gets tripped up here, and it's also the source of the "how do I exit vi?" joke, which exists because people open vi, type something, watch chaos happen, and have no idea how to leave.
- Normal mode is where vi starts. Keystrokes are commands, not text. For example, pressing the
ikey does not type the letter i, it switches to insert mode. - Insert mode is where typing works the way it does everywhere else. Get here by pressing
i(insert before the cursor) ora(append after the cursor) from normal mode. - Command mode is for saving, quitting, and other file-level operations. It is entered by pressing the : key when in normal mode, and puts a colon prompt at the bottom of the screen.
- The
Esckey always returns to normal mode. When in doubt,Escfirst, then decide what to do next.
Important Commands
Opening a file:
waltermoar-academy@webshell:~$ vi script.pywaltermoar-academy@webshell:~$ vi script.pyIf the file already exists, it will be opened for editing if the user has write permission to the file. If the file doesn't exist it will be created if the user has write permissions to the directory.
vi always starts in normal mode. To make an edit:
i enter insert mode
[type text]
Esc back to normal mode
:wq write (save) and quiti enter insert mode
[type text]
Esc back to normal mode
:wq write (save) and quitIn the sequence above it's important to remember to use Esc after typing text. The :wq command is the first one to remember: write, then quit. :q! is the exit to use when something has gone wrong while editing, and it's best to discard all unsaved changes and start over.
A few normal-mode commands cover most quick edits without ever entering insert mode:
dd delete the current line
yy yank (copy) the current line
p paste after the cursor
u undo
/text search forward for "text", Enter to jump to it, n for next matchdd delete the current line
yy yank (copy) the current line
p paste after the cursor
u undo
/text search forward for "text", Enter to jump to it, n for next matchA line can be jumped to directly with :n (for example, :42 jumps to line 42). This is useful when an error message points at a specific line.
Becoming Familiar with vi
The commands above are a start, but vi becomes powerful when used as the go-to editor. The more it's used for ordinary edits, the more the muscle memory builds, and advanced commands start being faster than a mouse-driven editor. Treating vi as the default rather than the backup is the long-term shortcut.
VS Code: The Heavyweight Option
When working locally, rather than inside a remote terminal session, a full graphical editor is sometimes preferred, and Visual Studio Code (VS Code) is a solid default. It provides syntax highlighting, a file browser, integrated terminal, and an enormous extension ecosystem, all without the modal-editing learning curve.
The caveat is right there in "local machine." VS Code doesn't run inside an SSH session or a CTF WebShell the way nano and vi do. It's worth knowing about for working with downloaded challenge files, writing solve scripts, or just being productive day to day, but the moment work moves into a remote terminal, it's vi or nano or nothing.
The real benefit of VS Code is when a challenge provides the source code, sometimes hundreds of files and thousands of lines, for an application. The editor is designed for working with source, and the file browsing, syntax highlighting, formatting, and other tools make it really easy to work with the code.
Why Editors Matter for Security
Editors and security go together more directly than they might seem to. Production incident response frequently happens over SSH, on a machine that is by design stripped down to reduce attack surface, meaning vi (or genuinely nothing else) is what's available when a config file needs an emergency fix at 3 in the morning. This is a real reason people have had to learn vi while already under stress, and it's a much better experience to already know it.
There's a second angle worth knowing about even without touching it hands-on: sudoedit and similar wrappers exist specifically because directly editing files as root with an arbitrary editor is a real privilege-escalation surface. Some editors can shell out to run arbitrary commands from within an editing session, and if that editor is running with elevated privileges, that shell-out runs with elevated privileges too. This shows up in privilege escalation checklists as something worth checking: does a permitted sudo command include an editor, and can that editor be used to break out to a shell?
Finally, the "vi is everywhere" property is itself a small security lesson: minimal, hardened systems deliberately have a small number of tools installed, because every additional installed tool is additional attack surface. A locked-down box with only vi and no nano isn't an oversight, it's often the point.
Summary
nano is the friendlier editor and worth knowing, but it isn't guaranteed to be installed. vi is almost always available, and that's the real argument for learning it properly rather than avoiding it: i to insert, Esc to return to normal mode, :wq to save and quit, :q! to discard changes and quit. dd, yy, p, and u cover most quick line edits, and /text handles search.
When a CTF challenge (or anything else) drops into an unfamiliar remote shell and a file needs editing, the reliable first move is to use vi. It's possible to check what else is there with which nano.
Want to learn more about security weaknesses? I'm working through the CWE list and doing writeups for security challenges. Follow along for more articles like this one.