That's Vimprovement! A Better vi
Vim has some interesting searching options. The first is the incremental searching option, which is enabled with the command:
:set incsearch
Normally when you do a search, say for include, you would enter the entire command: /include<CR> and Vim would start searching for the string. When incremental searching is enabled, Vim starts searching when you type the first character of the search. In other words, when you type /i, Vim searches for the first “i” in the text. Type the next character “n”, for /in and Vim looks for “in”. As you type each character the search moves on (if needed) to find the string that you've typed so far.
The other major innovation in searching is the highlight search (hlsearch) option. If this is enabled, then when Vim finds a string that matches a search, it highlights it. Not only is the current match highlighted, but all matches are highlighted.
This is useful if you're searching for a misspelled variable name or word, because all occurrences of the incorrect word are highlighted.
If you want highlighting to temporarily disappear, you can issue the the :nohl command. This clears the highlighting until the next search command is entered.
Vim also maintains a search history. Let's say you've done a number of searches. Now press / to start a search, and then the <UP> key. The previous search is displayed. Press <UP> again, and you get the next oldest search. Thus using the <UP> and <DOWN> keys you can scroll through a set of your recent searches.
One of the most powerful commands in Vim is the . (dot) command. It repeats your last edit. But this command is limited. It will only repeat a single command.
But what if you have something more complex to do? That's where Vim's keyboard macros come in. They allow you to record a series of commands in a register and then execute them.
To see how this works, let's suppose you have the following lines that you want to edit:
stdio.h time.h unistd.h stdlib.h
You want to make each of these into a #include line, e.g., #include <stdio.h>
You start by entering the command qa. This causes all subsequent commands to be recorded in register a. (Any register from a to z can be used.)
Next do the edits. Go to the beginning of the line (^) insert #include <, then finish by adding a > to the end of the line. Finally go down a line to be ready for the next edit.
All these commands are now recorded in the a register. The q command tells Vim to stop recording. The text now looks like:
#include <stdio.h> time.h unistd.h stdlib.h
with the cursor positioned on the second line. To execute the macro, use the command @a. The results are:
#include <stdio.h> #include <time.h> unistd.h stdlib.hThe @ command takes a repeat, so you can finish off our work using the 2@a command.
#include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h>
The command ctags (which comes with Vim) can be used to generate a program table of contents for a set of C files. (This is now a tags file.)
A typical ctags command is:
ctags *.c
This creates a tags file containing the location of all the functions in the C files in the current directory.
Once generated the tags file can be of great use to people editing with Vim.
Let's suppose you are editing a file and are looking at the read_paragraph function. As you go through the code you discover that read_paragraph calls read_sentence. You'd like to see what this function does.
If you position the cursor on the function name, and press CTRL-], Vim jumps to the definition of that function. You quickly discover that read_sentence calls read_word, so you position the cursor over read_word and press CTRL-]. Again the editor jumps to the definition of that function.
Vim keeps track of where you've been through the use of tag stack. To see where you are in this list, use the :tags command.
:tags # TO tag FROM line in file/text 1 1 read_sentence 3 read_sentence(); 2 1 read_word 8 read_word(); >
In this example, we've gone from read_word (not listed), to read_sentence and then read_word. To go back, use the CTRL-T command. It pops you up one level in the tag stack.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
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
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| 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 |
- Designing Electronics with Linux
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Using Salt Stack and Vagrant for Drupal Development
- Validate an E-Mail Address with PHP, the Right Way
- Build a Skype Server for Your Home Phone System
- Tech Tip: Really Simple HTTP Server with Python
- Why Python?
- A Topic for Discussion - Open Source Feature-Richness?
Enter to Win an Adafruit Pi Cobbler Breakout 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 Pi Cobbler Breakout 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
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




2 hours 26 min ago
6 hours 13 min ago
6 hours 21 min ago
8 hours 36 min ago
11 hours 5 min ago
21 hours 8 min ago
1 day 1 hour ago
1 day 5 hours ago
1 day 5 hours ago
1 day 8 hours ago