Self-written original program, let vim run c/c ++

Source: Internet
Author: User

Vim is a great editor with powerful scalability and supports almost all languages. There are many online methods for running C or C ++ debugging in VIM, but most of them are useless or complicated! As a result, I wrote a small program to implement it, which is very simple !!
The program storage directory is/python/c. py | c ++. py. There are two scripts in total:
The Code is as follows #! /Usr/bin/python
Import sys
Import OS
Arg = ''. join (sys. argv [1:])
If len (arg) = 0:
Print "file not exsits"
Sys. exit (1)
Else:

Gcc = 'gcc-Wall-G' + arg + '-O' + arg [: -2] # If you are running C ++, change the gcc-Wall to g ++-Wall.
If OS. system (gcc) = 0:
OS. system ('./% s' % arg [:-2])
1: Open the/etc/vimrc file, append two lines of vim. command ('map <C-C> :! /Python/c. py % <cr> ')
Vim. command ('map <C-G> :! /Python/c ++. py % <cr> ')

  • Ctrl + c run C
  • Ctrl + g run C ++
2: Test whether C runs successfully. 1 # include <stdio. h>
2
3/* main: generate some simple output */
4
5 int main (void)
6 {
7 printf ("Hello C's World. \ n ");
8 return 0;
9}

Display running results
:! /Python/c. py sklll. c
Hello C's World.
3: test whether C ++ is successful. 1 # include <iostream>
2
3 using namespace std;
4
5 int main (){
6 cout <"Hello C ++ World! "<Endl;
7
8 char response;
9 cin> response;
10
11 return 0;
12}

Running result
:! /Python/c ++. py test. c
Hello C ++ World!


OK. That's simple. Haha.







This article is from the Newbie's World blog, please be sure to keep this source http://skyson.blog.51cto.com/2497647/638943

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.