Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Let The Music Play: Join EFF Today

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 49 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here



Current HOWTO: C-editing-with-VIM-HOWTO


7. Quickfix

When coding in C one often has a edit-compile-edit cycle. Typically you would edit C file using some the things I've mentioned earlier, save the file, compile the code and go to the error(s) and start editing again. VIM helps save the cycle time slightly using a mode called quickfix. Basically, one has to save the compiler errors in a file and open the file with VIM using the command

	 $ vim -q compiler_error_file

VIM automatically opens the file containing the error and positions the cursor at the location of the first error.

There is a shortcut to the cycle. Using the command "make", one can automatically compile code and goto the position where the first error occurs. To invoke the make command type the following


Basically, this command calls make in a shell and goes to the first error. However, if you are not compiling using make and are compiling using a command such as cc, then you have to set a variable called makeprg to the command you want invoked when you use the make command. For eg. :set makeprg=cc\ foo.c

After setting makeprg, you can just call the make command and quickfix will come into play.

After you have corrected the first error, the next thing to do would be go to the next error and correct that. The following command is used go to the next error. :cn

To go back, you can use the command :cN

Let me demonstrate this using an example. Consider the following code

Figure 11. Quickfile Program Listing

As you can see there is an error on line number 5. The file is saved as test.c and makeprg is set using the command

	 :set makeprg=gcc\ test.c

Next the make command is invoked using the command :make. gcc gives an error and the output of the make command is something like this

Figure 12. :make error

On pressing RETURN, the cursor moves to line number 6.

Now, the command :cn will move the cursor to the line number 4.

To move back to the previous error, one can use the command :cN and the cursor will move back to the line 6.

After correcting the error on line 5 and adding "return 1;", one can run :make again and the output will be

Figure 13. No Error

That was just a small example. You can use quickfix to solve your compile time problems and hopefully reduce the edit-compile-edit cycle.

The Linux Tutorial completely respects the rights of authors and artists to decide for themselves if and how their works can be used, independent of any existing licenses. This means if you are the author of any document presented on this site and do no wish it to be displayed as it is on this site or do not wish it to be displayed at all, please contact us and we will do our very best to accommodate you. If we are unable to accommodate you, we will, at your request, remove your document as quickly as possible.

If you are the author of any document presented on this site and would like a share of the advertising revenue, please contact us using the standard Feedback Form.




Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.18 Seconds