VOOZH about

URL: https://thenewstack.io/get-to-know-vi-a-text-editor-for-the-ages/

⇱ Get to Know vi, a Text Editor for the Ages - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2020-01-04 06:00:13
Get to Know vi, a Text Editor for the Ages
tutorial,
Linux / Software Development

Get to Know vi, a Text Editor for the Ages

An introduction to vi, the default Linux text editor.
Jan 4th, 2020 6:00am by drtorq
👁 Featued image for: Get to Know vi, a Text Editor for the Ages

The vi text editor is found on nearly every Unix or Linux systems in existence, usually by default. I first used it a freshman at Purdue, in 1981. My second programming class, ran Unix on one of the big-iron university mainframes. Those were the pre-GUI (graphical user interface) days and everything was done via the command line, while basking in the comforting (eerie?) green-text glow of the old-school CRT (cathode ray tube) terminals. Purdue was phasing out punch cards and I had one class with them. Number your cards, is all I can say.

It was during those dark, sub-basement computer room late-nights that I passed into the ancient mystic netherworld of vi on Unix. Happily, here we are 39 years later and it is still my weapon of choice for text editing. Other popular, readily available Linux text editors exist, such as nano or emacs and do a right fine job. Not as easily as vi though, in my humble opinion.

Users growing up on strictly GUI or mouse-based editors might find command terminal-based vi intimidating. Don’t fret. We’re at the beginning of the roaring 2020s and there’s no better time to try something different. Give vi a fair try and I think you’ll see the value of a fast, no-drama text editor that works great across all your Linux servers, notebooks and microcontroller-based machines even including over remote (network or serial) connections. (Note, most distributions use an updated vi called VIM).

After a little while, vi might become an old friend to you too.

Buddy up to the ESC Key

Think of vi as a powerful, character or keyboard-based, minimalist text editor. By-the-way, vi can handle multi-megabyte text files, so hand-editing text-based, large data sets is possible without much fuss. Comma-separated value (.csv), HTML and json files come to mind.

In a Linux terminal, invoke vi with a filename. If the file already exists, you’ll simply be dropped into the text and can start editing from there. If the file doesn’t exist, it will create a new empty file. Here’s the command line for a new rob.txt file.

rob% vi rob.txt

👁 Image

Blank rob.txt file

Adding text is straightforward, keeping in mind that vi‘s methodology is character/key-based. Type the “i” character, for “insert” and add your desired text to the file. When finished hit the ESC key once to tell vi that you want to leave the “insert” function.

The escape key is an important vi mechanism used to conclude a command sequence. By default, vi accepts keyboard character/key combinations to do various functions, such as inserting text (with the “i” command), moving around in the file, replacing or deleting text and switching to command mode (with the “:” command).

vi‘s methodology is character/key based. Type the “i” character, for “insert” and add the your desired text to the file. When finished hit the ESC key once to tell vi that you want to leave the “insert” function.

That pretty much covers inserting text anywhere in a file. Move the cursor where you want to type. Use the “i” key to insert text, use the ESC key when finished. Go on to the next thing you want to add or change.

What if we already have some text and want to move down a few lines and insert a character or some text? Open an existing rob.txt file the same way.

rob% vi rob.txt

👁 Image

Existing rob.txt file

vi uses four basic navigation keys to move around in a file.

h – moves the cursor back one space
l – moves the cursor forward one space
j – moves to the next line
k – moves to the previous line

Say you want to add the letter “s” to the word “computer” down on line three in this rob.txt file. Use the “j” key to move down to line three. Now use the ‘l’ key to move over to the end of the word “computer”. Next, type the “i” (insert) key to insert a character, enter the letter “s” and follow up with the ESC key. After typing the ESC key, we are no longer inserting text and can freely move around again using the navigation h, l, j and k keys.

Notice that moving with the h, l, j and k keys minimizes your finger movement and lets you navigate around a file with one hand. I’ve been able to touch type since the ’70s and keeping your hand in one spot speeds things up a lot.

I habitually hit ESC after just about everything I do in vi. In fact, I occasionally catch myself punching the ESC key when editing my article files, up on WordPress and in LibreOffice.

Standard Method, Different Character

Deleting a text character works the same way as inserting. Move to the character you want to delete and type an “x”. Poof, the character will disappear from your screen. You can repeatedly use a string of x’s to delete a string of characters. Don’t forget to type the ESC key to end the delete function.

To replace a character use the “r” key. Move to the character you want to replace, type an “r”, then type your replacement character. Hit ESC to end the replace character function.

Suppose you want to search for a string of characters in your text file?

Use the “/” key. This one works slightly differently. Make sure you are in edit mode, by hitting the ESC key. Upon typing the “/” key you will be teleported to the bottom of the terminal edit window. Type in your search string. You might use “computer” in the rob.txt file. Hit Enter and vi will find the next instance of “computer” in the file. Type another “/”, followed by Enter and it will remember it’s looking for “computer” and go find the next instance. vi shows a prompt at the bottom, when it reaches the end of the file. Type “/” again to continue searching starting back up at the top.

Before we wrap up today’s tutorial, it might be nice to save our work.

Type a “:” to again teleport down to the vi command line at the bottom of the terminal window. Here you can use a whole host of additional key characters and combinations to really delve into the power of vi.

In our case, we just want to save our work in the file. Type ESC, then a “:”, then the “w” key. If you are editing an existing file, the file on the disk will be replace by your current edits. If it is a brand new blank file that’s never been saved, you can also give it a file name. I might start a new file and type “:” followed by “w”, then a space and then “rob.txt”. When editing a file, especially a large one, I use “w” fairly frequently.

Likewise, getting out of vi completely is as easy as typing the “:” key, then the “q” key. If you haven’t saved your work, you’ll probably get a “file not saved” prompt. I usually end my editing sessions with a “wq” combination. If you don’t want to save anything and just exit use the “q!” combination. Of course, if you start a blank file and for some reason change your mind, use “q” without doing any edits to just end your vi session.

What’s Next?

There you have it. A crash course in using vi on a Linux machine. I’d rather open a terminal, type vi and a file name and get right into editing, instead of going up to the desktop menu, finding a GUI/mouse-based editor and doing it that way.

Of course, I regularly use LibreOffice to write stories and bluefish to not very occasionally edit HTML files. My online posts are now done on exclusively WordPress, as well. We all have to be somewhat open-minded and flexible.

For quick text edits across my whole spectrum of Linux-based machines vi is my go-to app. Old programs that work for me might just be a new program that works great for you. Jump in and be a part of the Unix/Linux legacy.

Look for future Linux tutorials that delve deeper into using the vi text editor.

Contact Rob “drtorq” Reilly for consultation, speaking engagements and commissioned projects at doc@drtorq.com or 407-718-3274.

TRENDING STORIES
Rob "drtorq" Reilly is an independent consultant, writer, and speaker specializing in Linux/OSS, physical computing, hardware hacking, the tech media, and the DIY/Maker movement. He provides a variety of engineering, business and special project services to individual clients and companies....
Read more from drtorq
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.