Vim+makefile Getting started editing, compiling, error examples

Source: Internet
Author: User

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:

  1. #include<stdio.h>
  2. int main()
  3. {
  4. printf ("HI");
  5. }

Add the following parameters to the VIM command mode:

  1. : Set makeprg=g++\ hi.c\-o\ hi
  2. #gcc g++, you can remember to add a space after the backslash,
  3. #要不然执行起来连在一起, do not recognize
  4. : 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.

    1. hi:hi.c 
    2. 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

  1. #若完全正确, the following statement appears
  2. Press ENTER or type command to continue
  3. #若有错则出现, the following statement appears
  4. HI.C:1:error:missing terminating > character
  5. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.