That's Vimprovement! A Better vi
Vim has one new major mode: visual mode. In visual mode, highlight the text you want to edit, then type an editing command. In this example, you need to copy the first line of the function even from the bottom window and paste it in the top window.
Start by sending the cursor to the bottom window (CTRL-Wj) and positioning it on the first line of the function even. Next, enter line visual mode by typing the V command. The current line is highlighted, which indicates that this line will be affected by any editing command you type. At this point you can use the cursor commands to move the cursor down a few lines. As you move the cursor, the text that you pass over is highlighted. Move the cursor up, and it's unhighlighted. Go past the starting point, and the text above will be highlighted.
Highlighting is done on a line-by-line basis. That's because you've entered visual line mode. If you had typed v, for character visual mode, you could highlight text on a character by character basis. Finally, there is block visual mode (CTRL-V) that highlights a rectangle on the screen. This is good if you are working with text tables because you can manipulate columns of figures on the screen.
Now, to copy a single line from the bottom window to the top one, use line visual mode (V) and highlight that line. Then use the yank y command to copy it into the unnamed register. Next go to the top window and do a p to put (paste) the text into the top window. All you need to do now is add a “;” to the end of the line and you have an even header. Figure 3 shows these commands in action.
In order to compile our program we need a Makefile. (This exercise is left to the reader.)
Once our Makefile is in place we use Vim's integration with make to compile the program. All we need to do is issue the :make command from within Vim and the editor will run make and capture the output.
Our program contains an error:
even.c:4: parse error before `=='
Vim captures the output of the :make command and parses it. From this it can see that we have an error on line 4 of even.c, so it moves the cursor to this line and displays the error message at the bottom of the screen. (It will even switch files if it has to in order to locate the error.)
This makes it easy to fix the error. To see the next error, issue the :cn command. If you want to see the current error again, use the :cc command. The previous :cp. Finally, if you're done editing this file and want to see the first error in the next file use the :cnf command.
Vim is smart regarding the location of errors. When you add or delete lines at the start of the file, Vim adjusts the location of errors at the end of the file to reflect these changes. This avoids the problem you have with conventional editors like vi, where fixing an error at the start of a file throws off the line numbers for the rest of the file.
The grep command is great for finding out where a function is used and defined. Simply enter the command:
$ grep -n even *.c
and you get a printout of each line that contains the word even.
Vim has a :grep command that does the same thing. Actually this command is very similar to the :make command. It runs grep, captures the output and lets you navigate through the files using :cn, :cp, :cc, and :cnf.--just like :make.
If you turn on the cindent option, Vim will indent your program correctly when you insert new text. But what about the text that's already there? That's where the = command comes in.
It will run a block of text through Vim's internal indentation program. (Actually, you can select which program is to be used for indentation through the equalprog option.)
Let's see how this can work to indent a basic C statement block. There are two ways of invoking the = command. The first is to use ={motion}. The second is to enter visual mode, select a block of text and then press =.
So, one way to indent a block of code is to go to the first “{” of the block. Now enter =%. The = tells Vim to indent the text from here to where the next command takes the cursor. The next command in this case is %, which tells Vim to go to the matching “}”.
If you wanted to do things using visual mode, you would position the cursor on the first “{”, then enter line visual mode with the V command. Next position the cursor on the corresponding “}” using any set of commands that get you there. Finally, the highlighted block is indented with the = command.
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
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
| Android's Limits | Jun 04, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Linux Systems Administrator
- Introduction to MapReduce with Hadoop on Linux
- Senior Perl Developer
- Technical Support Rep
- Weechat, Irssi's Little Brother
- UX Designer
- One Tail Just Isn't Enough
- Android's Limits
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
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?





1 min 59 sec ago
49 min 55 sec ago
50 min 22 sec ago
3 hours 15 min ago
7 hours 25 min ago
7 hours 29 min ago
1 day 3 hours ago
1 day 4 hours ago
1 day 4 hours ago
1 day 7 hours ago