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