pctechguide.com

  • Home
  • Guides
  • Tutorials
  • Articles
  • Reviews
  • Glossary
  • Contact

Using vi to Edit Text Files on A Linux Dedicated Server

A fact of life with Linux administration is that you will have to edit text files, simply because the operating system is configured using text files. Although modern versions of Linux (try Knoppix) do provide friendly graphical desktops and GUI (graphical user interface) aids for most configuration tasks, a dedicated web server will not have these facilities available, so you simply have to get into the text.

The two most common programs used for editing text files from a command line interface are vi and emacs. We’ll look at vi in this article, as it is available on just about all default Linux installations. However, the fact is that vi is not an intuitive program to use, and will be completely alien to those used to editing files from Windows applications like Notepad. You will have to learn a completely new way of working, because there is no point and click operation at all, everything is achieved by entering keyboard commands.

Here we’ll cover the basic steps involved in editing text files with vi, so that you will have a reference to work from when it comes to editing the important administration files on your server. Don’t think that this is going to be a complex, exhaustive coverage of the operation of vi. Keeping it simple, we’re just covering the barebones essentials that will enable you to do what needs to be done.

Creating a file with vi

The steps to create a file with vi are actually very simple. Enter the following at the command line.

$ vi newfile.txt

(Please refer back to the conventions used here.) You’ll see something along the lines of this:

~

~

~

~

~

/home/[username]/newfile.txt [New File]

Now, anyone who’s never come across vi before will at this point be confused. If they start to type, then any number of weird things start to happen, but no text appears. There’s no icons or drop down menus, simply nothing to click on, and all those tildes (~) don’t make any sense. But relax, here’s what’s going on.

The vi editor has two modes, command or input. Whenever vi starts, it is in command mode, and is waiting to be told what you want to do. When you have a sparse or empty file, vi uses the tilde character as filler. To edit text, you have two options.

  • a – for add, allows you to input text that starts to the right of the cursor
  • i – for insert, allows you to input text that starts to the left of the cursor, which will be more familiar to most Windows users

Once you have hit either of these commands you are in the input mode and can edit the file. At any time you can get back to command mode by hitting the escape key. Go ahead and enter some text into the file. You’ll find you can type pretty much as you would normally type. You can:

  • hit return for a new line
  • use backspace and delete to delete characters
  • use the arrow keys to move around the text
  • use Home, End, Page up and Page Down

This is all pretty common stuff, but you might be a little frustrated if you’re used to using the Crtl to help you navigate a text file, as you’ll find it doesn’t work. However, when you’ve done editing, hit escape, and you’re back in command mode.

As an aside, a useful feature of vi is that when in command mode you can enter regular Linux shell commands, as long as you precede the command with :!. For instance, type:

:!pwd

This instruction will reveal your current directory location. Hit enter to return to vi. In this way you can navigate the operating system, list directory contents, move files, create directories, or whatever you need to do in the shell environment, without exiting vi. (See more on Linux directory structure and directory navigation.)

As for working with the text file, the table below outlines a useful subset of the vi instructions when operating in command mode. Try them out on your newly created file, and experiment. A few minutes now may help you to feel more comfortable when it comes to editing more important files later on.

Notice the differing cases for the letters, because a CAPITALISED letter does not mean the same thing as a lower case letter! And one more useful tip, if at any time you need to know the name of the file you’re editing and the line number you’re on, hit Ctrl-g to have a summary placed across the bottom of the screen.

VI COMMAND MODE INSTRUCTIONS
File Saving
ZZ or :wq Save the file and exit vi
:w Save the file
:q This quits the current file, but only if there are no unsaved changes
:q! The get-me-out-of-here! command, this quits vi without saving, so all changes are lost
Navigating Text
Arrow keys Move the cursor around the document
h(left), l(right), j(down), k(up) Alternatives to the arrow keys
w Moves the cursor to the beginning of the next word
b Moves the cursor to the beginning of the previous word
0 (zero) Moves the cursor to the beginning of the current line
$ Moves the cursor to the end of the current line
H Moves the cursor to the beginning of the first line currently on the screen
M Moves the cursor to the beginning of the middle line currently on the screen
L Moves the cursor to the beginning of the last line currently on the screen
Ctrl+f Go forward one page
Ctrl+b Go back one page
Ctrl+d Go forward half a page
Ctrl+u Go back half a page
G Go to the last line of the file
#G Move the cursor to the line number specified by #
Deleting text
x Deletes the character under the cursor
X Deletes the character before the cursor
dw Deletes from the current character to the end of the current word
d$ Deletes from the current character to the end of the current line
d0 Deletes from the current character to the beginning of the current line
Search and Replace
/text Search the file forward from the current cursor position for the text specified
?text Search the file backward from the current cursor position for the text specified
/some.*text Using regular expression-like wildcards, this will search for a line that contains the character string some followed by, after any intervening characters, the character string text
?[tT]ext Searches backwards for text or Text – remember that searches are case sensitive
:g/text Prints every line in the file that contains text
:s/text/replacement Replaces text with replacement on the current line
:g/text/s//replacement/g Replaces text with replacement in the entire file
:g/text/s//replacement/gp Replaces text with replacement in the entire file and displays the changes made onscreen
  • Advantage to Shared Web Hosting
  • Shared Hosting Issues – Shared Bandwidth and Server Resources
  • The Ins and Outs of Dedicated Web Hosting
  • When To Move To A Dedicated Server
  • Choosing a Dedicated Server for your Website
  • Managing and Operating a Dedicated Server Over the Internet Using Online Control Panels
  • Accessing the Linux Operating System on Dedicated Servers with PuTTY or SSH
  • How to Create a Secure Password
  • Using Sudo for Super User Access to Root Privileges in Linux
  • The Linux Directory Structure
  • Linux Commands for Navigating and Viewing Directories
  • Creating, Moving, Renaming and Copying Files and Directories in Linux
  • Find, View and Delete Files and Directories Using Linux Commands
  • Using vi to Edit Text Files on A Linux Dedicated Server

Filed Under: Moving from Shared to Dedicated Web Hosting Tagged With: editing text with vi, how to edit text files with vi, how to use the vi text editor

Latest Articles

Running Scrum retrospective meetings without Scrum Master

There are as many ways of conducting retrospective meetings as there are work teams. Today, we will try to describe a good formula to make the retrospective meeting more productive and find ways to improve team performance. Scrum methods involve a set of MEETINGS TO CREATE MORE POSITIVE DYNAMICS … [Read More...]

How to Get Started With Gambling at Online Casino

If you’re new to the world of gambling, starting out at an online casino can be a little daunting. With so many games and betting options available, where do you start? In this article, we’ll take you through the basics of how online casinos work, and give you some tips on playing with bonuses, … [Read More...]

Magneto-optical drives – MO technology

As implied by the name, these drives use a hybrid of magnetic and optical technologies, employing laser to read data on the disk, while additionally needing magnetic field to write data. An MO disk drive is so designed that an inserted disk will be exposed to a magnet on the label side … [Read More...]

Why Internet Bundles Are the Next Battleground for Gamers

A weak internet connection can turn seamless gaming sessions into frustrating experiences filled with lag, buffering or sudden disconnects. For … [Read More...]

Importance of Inbound Marketing in the Digital Age

A couple of months ago, Zacks reported that Hubspot was starting to make some major changes to its inbound marketing strategy. They talk a lot about … [Read More...]

Damage Control Strategies for Resolving Online PR Crises

Last July, Astrologer faced a major crisis after its CEO went viral at a ColdPlay concert when having an affair. This was just one of the many times a … [Read More...]

AI is Not Killing Computer Jobs Like Doomers Projected

There is no denying the reality that AI technology has played a massive role in disrupting our lives. A growing number of people claim that AI … [Read More...]

Everything You Need to Know About Sourcing Circuit Boards From U.S. Suppliers

In This Article This article includes: Why Source PCBs From the United States?How to Get a Quote From a U.S.-Based PCB ManufacturerThe Top U.S. … [Read More...]

Top Taplio Alternatives in 2025 : Why MagicPost Leads for LinkedIn Posting ?

LinkedIn has become a strong platform for professionals, creators, and businesses to establish authority, grow networks, and elicit engagement. Simple … [Read More...]

Guides

  • Computer Communications
  • Mobile Computing
  • PC Components
  • PC Data Storage
  • PC Input-Output
  • PC Multimedia
  • Processors (CPUs)

Recent Posts

What I Learned from a Major Web Design Project in Mexico

I recently had the honor of working closely with a major digital marketing company in Mexico. Due to the COVID-19 crisis, I had to socially distance … [Read More...]

SCSI Internal Connections

The SCSI devices inside a computer are attached to an internal SCSI cable. The last device on the cable must be terminated. Most internal SCSI … [Read More...]

Must Have WI-FI Router Features for the Office

The router is one of the most important pieces of hardware on a network. This is the device that basically shares the connection to the Internet among … [Read More...]

[footer_backtotop]

Copyright © 2026 About | Privacy | Contact Information | Wrtie For Us | Disclaimer | Copyright License | Authors