That's Vimprovement! A Better vi
The Linux system comes with a vi clone called Vim. However, this editor can do more than just mimic vi. It has literally hundreds of additional functions, including commands for a help system, multiple windows, syntax coloring, program compilation and error corrections, advanced searching and many more.
By default, Vim starts in vi-compatibility mode. This means that many of the advanced features are turned off. To turn on these Vim improvements you need to create a $HOME/.vimrc file.
Listing 1 contains a sample .vimrc file. You can also create one by copying your .exrc file if you have one. A zero length file works as well.
There are two flavors of the Vim editor. The command vim starts the console version of the editor. In this version, you edit inside the terminal window in which you executed the command. The gvim command creates its own window. This second command is preferred because you get features, such as a command menu and toolbar, not found on the console version.
One of the most useful innovations that Vim has is the on-line, integrated help.
The :help command displays a help window. For specific help :help / displays the help text for the search (/) command (see Figure 1).
You can move through this text using the normal editing commands, such as h, j, k, l, <Page-Up>, <Page-Down>, etc.
As you scroll through the text, you'll see some lines that look like
/<CR> Search forward for the [count]'th latest used
pattern |last-pattern| with latest used |{offset}|.
The text enclosed in vertical bars (|) is a Vim hyperlink. Position the cursor over one of these items (say |last-pattern|) and press CTRL-]. This will make the screen jump to the given subject.
To go back to where you were before the jump, use the command CTRL-T.
To get out of the help system, use the normal Vim exit commands :q or ZZ.
To see how some of the new Vim commands can help you, start by creating a simple program file containing the following text:
#include "even.h"
int even(int value)
{
if (value & 1) == 1) // Deliberate mistake
return (1);
return (0);
}
The first thing to notice is the changing colors of the text. This is called syntax highlighting. Each component of a program (keyword, string, constant, preprocessor directive, etc.) gets a different color. In our initialization file, this was enabled by the :syntax on command. If you do a :syntax off, the highlighting disappears.
The next thing to note as you type in the file is that you don't have to do any indenting. All the lines are automatically indented for you. This is because of the cindent option being turned on by the magic lines:
:autocmd FileType c,cpp :set cindent
This applies to C and C++ files only. (Unfortunately a full discussion of autocommands is beyond the scope of this article. You can do a :help autocmd for full instructions.)
Note: The actual commands in the sample .vimrc file are a little more fancy than the ones presented in this section, but they do the same thing.
Now, let's have a little fun. Position the cursor on the “r” of one of the return statements and type xxxxxx. The return disappears. Now type “u” to undo the last change. The “n” returns.
The old vi editor had only one level of undo. Vim has many. Type “u” again, and notice that you've got “rn” back. Type “u” four more times and the whole word returns.
So how do you undo an undo? Through the new “redo” command:' CTRL-r. By typing this a couple of times, you redo the delete, which causes parts of “return” to disappear.
Now that you have a C file, you should create a header. It would be nice to be able to copy and paste the prototype from the C file into the header. With vi you couldn't do this. With Vim, it's easy.
First, bring up both files in the editor. The command :split even.h splits the current window in two. The top-half gets the file even.h, and the bottom even.c (see Figure 2).
To move the cursor from the top window to the bottom window use the command CTRL-Wj. To move up a window, use the command CTRL-Wk.
To close a window, use the ZZ or :quit command.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- RSS Feeds
- New Products
- Using Salt Stack and Vagrant for Drupal Development
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- Validate an E-Mail Address with PHP, the Right Way
- New Products
- Readers' Choice Awards
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.






5 hours 24 min ago
11 hours 23 min ago
11 hours 46 min ago
11 hours 56 min ago
12 hours 46 sec ago
12 hours 30 min ago
15 hours 22 min ago
15 hours 57 min ago
15 hours 58 min ago
15 hours 59 min ago