Vim one-click Compilation

Source: Internet
Author: User
Tags imap
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>
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.