Publishers of technology books, eBooks, and videos for creative people

Home > Articles

Creating and Editing Files in Unix and Linux

  • Print
  • + Share This
In this chapter from Unix and Linux: Visual QuickStart Guide, 5th Edition, learn two of the most common editors: nano and vi. This chapter offers a general overview of each, and then discusses some how-tos of using each one.
This chapter is from the book

Creating and editing files are likely the most common tasks you’ll perform in Unix or Linux. If you’re programming, developing webpages, sending email (uh-huh, really), writing a letter, configuring your environment (see Chapter 8), or just exploring the system, you’ll spend a lot of time in an editor.

In this chapter, we’ll introduce you to two of the most common editors: nano and vi. We’ll launch this chapter with a general overview of each, and then discuss some how-tos of using each one. With the information presented here, you’ll be able to choose an editor based on your needs and get started using it (or using both of them).

Choosing an Editor: nano/pico or vi/vim

Basically, all editors are designed to do the same things: enable you to create, modify, and save text files. These files could include configuration files, email messages, or shell scripts—essentially any text file you can create. Which editor you choose is up to you, depending on your specific needs and how much you’re willing to learn.

In this book, we’ll stick to the two biggies: nano and vi, which will likely give you all the capabilities you’ll need. We chose these because nano is (arguably) the easiest Unix or Linux editor to use and vi is one of the most powerful and is available on almost every Unix or Linux system.

Which to choose? We recommend that you explore both. While you’ll no doubt find nano easier to use, we highly recommend that you make a concerted effort to learn to get around in vi. You’ll find that vi’s learning curve is steeper—much—but that being a skilled vi user will provide many benefits, not the least of which is that vi is really the only editor you can count on being on any Unix or Linux system you use.

About nano or pico

nano is one of the more straightforward Unix editors and has become quite popular because it’s extremely easy to use. In particular, as shown in red_a.jpg, it’s menu-driven and intuitive. All the commands are visible, and you can open, modify, and close files with little effort. nano is a great choice if you’re just getting started with Unix or Linux, or if you won’t be needing an editor able to leap tall files in a single bound.


Click to view larger image

red_a.jpg nano offers onscreen command reminders to make it easier to use.

For a variety of reasons, mostly connected to open-source licensing issues, nano is a near-clone of pico, which in the past was included in a number of Linux/Unix distributions as well as on systems that you might be using today. The nano editor is command-for-command the same as pico, but it does offer some supplemental higher-end (yet still easy-to-use) features.

For the purposes of this book, we’re going to treat pico and nano as equivalent—if you have pico, just mentally write that in wherever you see nano.

pico is distributed with the pine email program, so if you have pine available to you, you likely also have pico. (See Chapter 1 for a reminder on how to find out if specific programs are available to you.) If pico is not available to you, and if you cannot find nano either, ask your system administrator to install one or the other.

About vi or vim

Although vi is likely responsible for much of Unix’s and Linux’s reputation for being complicated and confusing, it offers enormous power and flexibility. Plus, vi is universally available (unlike nano), so for these two reasons, you should consider taking the time to learn it. You might find vi cryptic, counterintuitive, and nitpicky, and for this reason, you might want to choose a different editor if you won’t require vi’s capabilities. As red_b.jpg shows, if you use vi, you won’t have menus at your disposal—you’ll have to get used to using commands like esc.jpg:q or esc.jpg:%s/vi is arcane/vi is powerful/.


Click to view larger image

red_b.jpg vi gives you a clean screen and makes you remember all of its cryptic commands.

Yes, continuing the theme from the previous section, there is an equivalent of vi, called vim, that’s licensed differently and that’s somewhat more powerful. For basic use—everything in this book and far more—the two are identical. In this case, though, you will always find vi, even if it’s really vim (vi may actually be a symlink, or shortcut, to vim). If you find vim, though, it will assuredly be vim. All commands will be the same, so just dive in and enjoy.

  • + Share This
  • 🔖 Save To Your Account