4 Text Editors and Vim
Text Editors

Wikipedia contributors. (n.d.). Text editor HTML. Wikimedia Commons. https://commons.wikimedia.org/wiki/File:Text_editor_HTML.png
A text editor is a computer program that, as the name implies, enables you to edit plain text. They work somewhat like a version of Google Docs or Microsoft Word. There are many programs that will do text editing. You may have used NotePad or a similar program on your own computer. If you ever have to modify a script or configuration file on a remote machine, the it will be necessary to use a terminal-based text editor. There are many programs that will do text editing. Although there are several other command line editors such as nano and emacs, we will focus this chapter on Vim, as it is the tool of choice in VCL.
Vim
Vim, originally known as VI (short for visual editor), is a Unix-based text editor designed for efficient text editing. This application runs in a terminal and can be entirely controlled using the keyboard, eliminating the need for a mouse or graphical menus. While this may feel counterintuitive at first, with practice you will find this enhances both editing speed and efficiency. Vim is highly customizable, allowing users to tailor their desired workflow by configuring personal key bindings and installing plugins. Vim is able to be used in many programming languages and different tasks.
Entering and Exiting Vim
![]() |
![]() |
---|
(VCL, 2025)
The most common way to enter vim is to type vim filename.txt
into the terminal. Replace filename.txt
with the actual name of your file. If filename.txt
does not yet exist, Vim will create a blank document for you to edit; press i to start typing in the document. You can also type vim followed by the file path to the file you want to edit. To exit vim, you can enter either :wq
to save your changes and exit, or :q!
to exit without saving.
Modes in Vim
Modes in Vim are different states that change the editor’s behavior depending on the current mode the user is in. The three primary modes are normal, insert, and command, with an additional visual mode.
- Normal Mode: The default mode of Vim, where users can navigate through the file, and perform actions like adding, deleting, or copying text using keyboard shortcuts. You can return to normal mode by pressing the esc key.
- Insert Mode: Accessed by pressing the
i
key, this mode functions similarly to a word processor, allowing developers to type and edit text directly. You will not be able to add text to your document unless you are in insert mode. - Command Mode: Accessed by pressing the
:
key, this mode is where developers execute commands such as undo, replace, save, quit, and more. - Visual Mode: Accessed by pressing the
v
key, this mode allows users to highlight text, showing which words or lines will be affected by the given command.
Note: you’ll need to be in normal mode to enter the other three modes; you cannot move directly from insert mode to visual mode, for example.
Vim Cheat Sheet
Global Commands | Description of Command |
---|---|
:help <keyword> |
Opens help for <keyword> |
:o <fileName> |
Opens <fileName> |
:saveas <fileName> |
Saves file as <fileName> |
:close |
Closes current window |
tabnew |
Opens a file in a new tab |
tabclose |
Closes the current tab |
Cursor Commands (Normal Mode) | Description of Command |
---|---|
:h, j, k, l |
Left, down, up, right (respectively). In newer versions of Vim, using the keyboard arrows also works. |
w |
Move forward one word |
b |
Move back one word |
0 |
Jump to the start of the line |
$ |
Jump to the end of the line |
gg |
Jump to the first line of document |
G |
Jump to the last line of document |
Entering Insert Mode | Description of Command |
---|---|
i |
Enter insert mode |
A |
Insert (append) after cursor |
o (lowercase) |
Append (open) a new line below the current line and enter insert mode |
O (uppercase) |
Append (open) a new line above the current line and enter insert mode |
Ea |
Insert (append) at the end of the current word and enter insert mode |
Esc |
Exit insert mode |
Editing (Normal Mode) | Description |
---|---|
r |
Replace single character. For example, to change “a” to “b”, navigate to “a” and type rb . |
Cc |
Change entire line |
Cw |
Change word (deletes word and enters insert mode) |
c$ |
Change and replace to the end of the line |
U |
Undo |
ctrl-r |
Redo |
. |
Repeats last command |
yy |
Copy line |
Yw |
Copy current word |
y$ |
Copy to the end of the line |
p |
Paste after cursor (P pastes before cursor) |
dd |
Deletes a line |
dw |
Deletes a word |
x |
Deletes a character |
Find and Replace | Description |
---|---|
/\<pattern\> |
Search for <pattern> |
?\<pattern\> |
Search backwards for <pattern> |
:s/<old>/<new> |
Replaces all instances of <old> with <new> on current line |
:%s/<old>/<new>/g |
Replaces all instances of <old> with <new> throughout the document |
:%s/<old>/<new>/gc |
Replaces all instances of <old> with <new> and asks for confirmation |
Exiting | Description |
---|---|
:w |
Saves the file, but does not exit |
:wq or :x or ZZ |
Saves the file and exit |
:q! |
Exit without saving changes |
Examples
- You open a file with Vim and execute the following series of commands: j, j, dd, G. Where are you in the file, and what have you done your editing?
Answer: It’s helpful to work through the commands one at a time. By default, we start at the top of the file (i.e., line 1). The first “j” command goes down one line. When we repeat the command, we go down another line. We are now on line 3. The “dd” command deletes the line we are on (line 3). The “G” command takes us to the bottom of the file. Therefore, we are at the bottom of the file, and the original line 3 was deleted.
- Your lab member comes to you in a panic because they don’t remember how to exit Vim. They tell you that they have been typing “wq”, but this shows up in their script. What did they miss?
Answer: They need to move from insert mode to command mode by pressing colon (:). The key sequence :wq
will exit Vim.
- Mark is trying to turn a bad letter of recommendation into a positive one. He wants to replace every instance of “awful” into “awesome”. How can he do this in Vim?
Answer: This is a case for find and replace. The line :%s/awful/awesome/g
would get the job done. I would recommend using :%s/awful/awesome/gc
so that he can confirm that each change is what he wants. But if he’s in this situation, he’s probably not careful enough to do this.
Further Reading
We recommend the following sources for more information on this topic:
Greene, M.R. Big Data Summer School
Editors (Vim) from MIT’s “Missing Semester” course.