Vim+makefile Getting started editing, compiling, error instance vimmakefile compiling
Write code, generally in vim after editing, input: Wq, in the command line input g++ Hello.cc-o Hello, there is a problem, open vim, find the corresponding line modification, feel is not very annoying very nc. In fact, the Quickfix list from Vim can help us compile code and navigate through error messages without having to quit vim.
Simple debugging of individual files, just add environment variable MAKEPRG.
Write a simple program named HI.C as follows:
- #include<stdio.h>
-
- int main()
- {
- printf ("HI");
- }
Add the following parameters to the VIM command mode:
- : Set makeprg=g++\ hi.c\-o\ hi
- #gcc g++, you can remember to add a space after the backslash,
- #要不然执行起来连在一起, do not recognize
- : Make #执行make即可
Note: C is consistent with C + + program effect
Write a simple makefile for a single file
-
make command can be performed using the makefile via-F. If the-F designation is not used, it is executed in the following order.
Gnumakefile, makefile, and makefile
recommend the name of makefile, and Gnumakefile is not recommended, it is used only for specific versions of GNU make.
-
- hi:hi.c
- g++-O hi hi.c
- Input in the VIM command line: Make, the effect is the same as the first class
The difference: The general large-scale system are makefile, do not need to edit their own, it is generally used the second method, but the first method suitable for their own programming and testing, convenient and quick.
Using Quickfix for error troubleshooting
Input under Vim: Make
- #若完全正确, the following statement appears
- Press ENTER or type command to continue
- #若有错则出现, the following statement appears
- HI.C:1:error:missing terminating > character
-
- Press ENTER or type command to continue
If something goes wrong, press ENTER to go back to vim, type: CW and start tuning.
command |
purpose |
:cn[ext] |
Jump to the next item (error) |
:cp[rev] |
Jump to previous item (error) |
:cl |
list all errors |
:CC |
Show error details |
:copen |
open quickfix window |
:cclose |
close quickfix window |
:col |
to the previous old error List |
: cnew |
To the next more recent Error List |
Vim+makefile Getting started editing, compiling, error examples