Method 1
Go to the vim official website under the CVIM plug-in (http://www.vim.org/scripts/script.php? Script_id = 213). If not, go to the vim official website and enter the CVIM keyword to search.
Decompress the package directly to your. Vim folder (that is, a folder dedicated to the vim plug-in)
Then run the following command (only for C and C ++ files, and other files are invalid ):
F9compile and link
Alt-F9write buffer and compile
Ctrl-F9run executable
Shift-F9set command line arguments
Shift-F2switch between source files and header files
Method 2 (you can add a compilation run such as Java, which is very simple)
Add the following to the vim configuration file:
"Compile C source file
Fun! Compilegcc ()
Exec "W"
Let compilecmd = "! Gcc-wall-ANSI-pedantic-STD = c99"
Let compileflag = "-o % <"
Exec compilecmd. "%". compileflag
Endfunc
"Compile C ++ source files
Fun! Compilecpp ()
Exec "W"
Let compilecmd = "! G ++-g-wall-pedantic-STD = C ++ 98"
Let compileflag = "-o % <"
Exec compilecmd. "%". compileflag
Endfunc
"Automatically select the corresponding compilation function based on the file type
Func! Compilecode ()
Exec "W"
If & filetype = "C"
Exec "Call compilegcc ()"
Elseif & filetype = "CPP"
Exec "Call compilecpp ()"
Endif
Endfunc
"Run executable files
Func! Runresult ()
Exec "W"
If & filetype = "C"
Exec "! % <"
Elseif & filetype = "CPP"
Exec "! % <"
Endif
Endfunc
"<F7> one-click saving and compilation
Map <F7>: Call compilecode () <CR>
Imap <F7> <ESC>: Call compilecode () <CR>
Vmap <F7> <ESC>: Call compilecode () <CR>
"<F5> one-click saving and running
Map <F5>: Call runresult () <CR>
Imap <F5> <ESC>: Call runresult () <CR>
Vmap <F5> <ESC>: Call runresult () <CR>