Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 38

Warning: include(http://www.linux-faqs.com/HOWTO/header.inc) [function.include]: failed to open stream: no suitable wrapper could be found in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 38

Warning: include() [function.include]: Failed opening 'http://www.linux-faqs.com/HOWTO/header.inc' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 38

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 39

Warning: include(http://www.linux-faqs.com/HOWTO/header.bottom.inc) [function.include]: failed to open stream: no suitable wrapper could be found in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 39

Warning: include() [function.include]: Failed opening 'http://www.linux-faqs.com/HOWTO/header.bottom.inc' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 39
 
FAQS
» Advanced Routing & Traffic Control
» General FAQ
» Squid Proxy Server
» Sendmail
» Fetchmail
» Postfix
» Connecting Mobile Phone
» Paging from Linux
» Standard Commands
» Some common terms
HOW-TOs
» ADSL Bandwidth Management
» Compile Apache
» Make a Bootdis
» Linux-Windows9x-Grub
» Linux-Windows
» Linux Crash Recovery
» Optimise Squid
» Block websites in Squid
» broadcast webcam in linux
» Compile RedHat Linux kernel
» Implement Firewall Security
» Increase Harddrive Performance
» Mount NTFS filesystem
» Patch / rebuild SRPM
» Secure Linux
» Set up a DHCP Server
» Set up an FTP server
» Set up Linux as a Router
» Use Cron
Miscellaneous
» All Ports
» Hardware Guides
» Hardware Review Guides
» Fav Troubleshooting forums
» Spammers fetch email addresses
» Mounting NTFS in linux


 

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

	 
:make

      

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.


 
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 357

Warning: include(http://www.linux-faqs.com/HOWTO/body.right.inc) [function.include]: failed to open stream: no suitable wrapper could be found in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 357

Warning: include() [function.include]: Failed opening 'http://www.linux-faqs.com/HOWTO/body.right.inc' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 357


 

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 362

Warning: include(http://www.linux-faqs.com/HOWTO/footer.inc) [function.include]: failed to open stream: no suitable wrapper could be found in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 362

Warning: include() [function.include]: Failed opening 'http://www.linux-faqs.com/HOWTO/footer.inc' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php') in /home/.showoff/linuxfaqs/linux-faqs.com/HOWTO/C-editing-with-VIM-HOWTO/quickfix.php on line 362