sponsor Vim development Vim logo Vim Book Ad

SingleCompile : Make it more convenient to compile or run a single source file.

 script karma  Rating 261/88, Downloaded by 11815  Comments, bugs, improvements  Vim wiki

created by
Hong Xu
script type
Homepage: http://singlecompile.topbug.net

This plugin is aimed at making it more convenient to compile or run a single
source file without leaving vim.

A short introduction is available here: http://www.topbug.net/blog/2012/03/07/use-singlecompile-to-compile-and-run-a-single-source-file-easily-in-vim/

Consider this situation: you have just written a small c source file for a
small test, but you have to write a Makefile to compile it or exit vim to
compile it or compile it using "!gcc" without quickfix feature because vim's
make command only use the "make" command? This plugin will help you out.

Add these key-mappings to your vimrc:

nmap <F9> :SCCompile<cr>
nmap <F10> :SCCompileRun<cr>

Note that the two lines here should not have any trailing space. If your file
type is supported, then press F9 to compile your source file, and press F10 to
compile and run your source file. If there is a compilation error, and the
|quickfix| feature is enabled, then you could use |:cope| command to see the
error list. You may also use ":SCChooseCompiler" command to choose a compiler
if you have more than one kind of compiler available on you system.
":SCViewResult" will show you the last run result.

1. Compile or run the source file quickly using quickfix feature and compiler feature of vim;
2. Compilers and interpreters auto detecting;
3. Fast switch between several installed compilers or interpreters;
4. Multi-language support;
5. Custom your own compiler/interpreter template;
6. View the result of last run command at any time(requires "tee" command);
7. Run the compiled program asynchronously and view the result at any time
   (see :SCCompileRunAsync in the help file).

Here is a list of built-in supported compilers or interpreter(For some
compilers, you need to set the environment varibles correctly to make them
available for SingleCompile):

    gnat (GNAT)

    bash (Bourne-Again Shell)

    bcc (Borland C++ Builder), Windows only
    cc (UNIX C Compiler), UNIX only
    ch (SoftIntegration Ch)
    clang (the Clang C and Objective-C compiler)
    gcc (GNU C Compiler)
    icc (Intel C++ Compiler)
    lcc (Little C Compiler)
    msvc (Microsoft Visual C++ (In PATH)), Windows only
    msvc80 (Microsoft Visual C++ 2005), Windows only
    msvc90 (Microsoft Visual C++ 2008), Windows only
    msvc100 (Microsoft Visual C++ 2010), Windows only
    msvc110 (Microsoft Visual C++ 2012), Windows only
    open-watcom (Open Watcom C/C++32 Compiler)
    open64 (Open64 C Compiler), UNIX only
    pcc (Portable C Compiler)
    sol-studio (Sun C Compiler(Sun Solaris Studio)), UNIX only
    tcc (Tiny C Compiler)
    tcc-run (Tiny C Compiler with "-run" Flag)

    bcc (Borland C++ Builder), Windows Only
    ch (SoftIntegration Ch)
    clang (the Clang C and Objective-C compiler)
    g++ (GNU C++ Compiler)
    icc (Intel C++ Compiler)
    msvc (Microsoft Visual C++ (In PATH)), Windows only
    msvc80 (Microsoft Visual C++ 2005), Windows only
    msvc90 (Microsoft Visual C++ 2008), Windows only
    msvc100 (Microsoft Visual C++ 2010), Windows only
    msvc110 (Microsoft Visual C++ 2012), Windows only
    open-watcom (Open Watcom C/C++32 Compiler)
    open64 (Open64 C++ Compiler), UNIX only
    sol-studio (Sun C++ Compiler(Sun Solaris Studio)), UNIX only

    msvcs(Microsoft Visual C#), Windows Only
    mono (Mono C# compiler)

    cmake (cmake)

    coffee (CoffeeScript)

    csh (C Shell)
    tcsh (TENEX C Shell)

    dmd (DMD Compiler)

dos batch:
    dosbatch (DOS Batch)

    escript (Erlang Scripting Support)

    ftn95 (Silverfrost FTN95), Windows only
    g77 (GNU Fortran 77 Compiler)
    g95 (G95)
    gfortran (GNU Fortran Compiler)
    ifort (Intel Fortran Compiler)
    open-watcom (Open Watcom Fortran 77/32 Compiler)
    open64-f90 (Open64 Fortran 90 Compiler), UNIX only
    open64-f95 (Open64 Fortran 95 Compiler), UNIX only
    sol-studio-f77 (Sun Fortran 77 Compiler(Sun Solaris Studio)), UNIX only
    sol-studio-f90 (Sun Fortran 90 Compiler(Sun Solaris Studio)), UNIX only
    sol-studio-f95 (Sun Fortran 95 Compiler(Sun Solaris Studio)), UNIX only

    go (Go)

    ghc (Glasgow Haskell Compiler)
    runhaskell (runhaskell)

    arora (Arora)
    chrome (Google Chrome)
    chromium (Chromium)
    epiphany (Epiphany)
    firefox (Mozilla Firefox)
    ie (Microsoft Internet Explorer)
    konqueror (Konqueror)
    opera (Opera)

IDL(Interactive Data Language):
    idl (ITT Visual Information Solutions Interactive Data Language)
    gdl (GNU Data Language incremental compiler)

    gcj (GNU Java Compiler)
    sunjdk (Sun Java Development Kit)

    gjs (Javascript Bindings for GNOME)
    js (SpiderMonkey, a JavaScript engine written in C)
    node.js (node.js)
    rhino (Rhino, a JavaScript engine written in Java)

    ksh (Korn Shell)

    latex (LaTeX)
    pdflatex (pdfLaTeX)
    latexmk (Automatic LaTeX document generation routine)

    clisp (GNU CLISP)
    ecl (Embeddable Common-Lisp)
    gcl (GNU Common Lisp)

    lsc (LiveScript)

    lua (Lua Interpreter)

    gmake (GNU Make)
    nmake (Microsoft Program Maintenance Utility)
    mingw32-make (MinGW32 Make)

    markdown (text-to-HTML conversion tool)
    rdiscount (Discount Markdown Processor for Ruby)
    Markdown (Python implementation of the Markdown language)

    matlab (MathWorks MATLAB)
        Note: For Matlab, I highly recommend you to try out vim-matlab-behave plugin: https://github.com/elmanuelito/vim-matlab-behave
    octave (GNU Octave)

    clang (the Clang C and Objective-C compiler)
    gcc (GNU Object-C Compiler)

    fpc (Free Pascal Compiler)
    gpc (GNU Pascal Compiler)

    perl (Perl Interpreter)

    php (PHP Command Line Interface 'CLI')

    ironpython (IronPython)
    jython (Jython)
    pypy (PyPy)
    python (Python Interpreter, usually the system default Python, no matter it is Python 2 or 3.)
    python2 (Python 2 Interpreter)
    python3 (Python 3 Interpreter)

    qmlscene (QML Scene, for viewing QML based on QtQuick 2)
    qmlviewer (QML Viewer, for viewing QML based on QtQuick 1)
    Note: vim does not detect qml files out of the box.
    See https://github.com/peterhoeg/vim-qml

    R (R)

    rst2html (reST to HTML)

    ruby (Ruby Interpreter)
    jruby (Ruby on top of Java JVM, default mode)
    jruby1.8 (Ruby on top of Java JVM, Ruby 1.8 mode)
    jruby1.9 (Ruby on top of Java JVM, Ruby 1.9 mode)
    jruby2.0 (Ruby on top of Java JVM, Ruby 2.0 mode, requires JRuby 1.7.4 or

    rustc (Rust compiler)

    scala (Scala compiler)
    Note: vim does not detect scala files out the box.
    See https://github.com/bjartek/scala-vim-support

    ash (Almquist Shell)
    bash (Bourne-Again Shell)
    dash (Debian Almquist Shell)
    ksh (Korn Shell)
    sh (Bourne Shell)
    zsh (Z Shell)

    tclsh (Simple shell containing Tcl interpreter)

    tcsh (TENEX C Shell)

vb script:
    vb (VB Script Interpreter)

    arora (Arora)
    chrome (Google Chrome)
    epiphany (Epiphany)
    firefox (Mozilla Firefox)
    ie (Microsoft Internet Explorer)
    konqueror (Konqueror)
    opera (Opera)

    zsh (Z Shell)

You can add your compiler or interpreter support if the compiler or
interpreter you want is not in the list. See details in the help file

There are some supporting code in this plugin for Marc Weber's

Feedback is welcome. If you find any bug or have some good ideas to
improve this plugin, please feel free to report it to hong@topbug.net
or submit it on the issue tracker:


If you've written some templates for some compilers or interpreters which are
not included as built-in template, and you think they are useful for other
people, you could send me an email to inform me, and I'll put them in the
built-in templates.

Git Repository:  https://github.com/xuhdev/SingleCompile

Check the wiki pages for some tips: https://github.com/xuhdev/SingleCompile/wiki/_pages

Follow xuhdev on twitter if you are interested in my development:
install details
   Download the SingleCompile.zip file and extract it to your vim runtime
directory(~/.vim in UNIX/Linux and $VIM_INSTALLATION_FOLDER\vimfiles in windows).

add "filetype plugin on" to your vimrc if you haven't done it.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
SingleCompile-2.12.0.zip 2.12.0 2014-06-11 7.2 Hong Xu Fish Shell is supported;
Added builtin template: CoffeeScript, LiveScript, octave, JRuby, markdown.py, QML;
Support vertical splits on SCViewResult (See the g:SingleCompile_split option);
Many bug fixes.
SingleCompile-2.11.0.zip 2.11.0 2013-05-20 7.0 Hong Xu Add g:SingleCompile_quickfixwindowposition option to control the quickfix window position when popped up by SingleCompile;
Add g:SingleCompile_usetee option to enable and disable the use of `tee` (By zhou13).
SingleCompile-2.10.7.zip 2.10.7 2013-02-14 7.0 Hong Xu Add built-in template for go, rst, latexmk, and scala (note vim does not detect scala files out of the box. You may need to see https://github.com/bjartek/scala-vim-support);
Optimize the built-in python template;
many minor bug fixes.
SingleCompile-2.10.6.zip 2.10.6 2012-07-31 7.0 Hong Xu Fix cmake and dosbatch builtin template issues;
Add rst2html builtin template.
SingleCompile-2.10.5.zip 2.10.5 2012-05-15 7.0 Hong Xu Fix an issue that if quickfix opens another file with a different file title when compiling, the run fails.
SingleCompile-2.10.4.zip 2.10.4 2012-05-09 7.0 Hong Xu Add markdown builtin template;
split builtin templates into small files;
a variety of bug fixes.
SingleCompile.zip 2.10.3 2012-04-15 7.0 Hong Xu Do some code cleanup.
Release the final version of 2.10.x.
SingleCompile-2.10.2-beta.zip 2.10.2beta 2012-03-22 7.0 Hong Xu g:SingleCompile_showquickfixiferror option now supports interpreting languages on UNIX (not on Windows yet);
some minor improvements.
SingleCompile-2.10.1-beta.zip 2.10.1beta 2012-03-02 7.0 Hong Xu Some improvements for the result view window (by John Tyree);
:SCChooseCompiler will display the current active compiler.
some minor bug fix if the result is set to be displayed right after compilation (by John Tyree).
SingleCompile-2.10.0beta.zip 2.10.0beta 2012-01-23 7.0 Hong Xu Implement old style template settings in a better way (Should make the plugin work faster and the code cleaner);
Add node.js built-in template for javascript. (By flebber)
SingleCompile-2.9.3.zip 2.9.3 2012-01-11 7.0 Hong Xu Add gjs(Javascript Bindings for GNOME) built-in template;
add an important note in the key mapping part of the doc (reported by flebber);
add git repo URL to the doc;
add License header.
SingleCompile-2.9.2.zip 2.9.2 2011-11-21 7.0 Hong Xu Fix a problem that function SingleCompile#SetCompilerTemplateByDict cannot change compilers' priority;
Fix an issue that Borland C Compiler built-in template cannot successfully compile a C and C++ source file;
Add priority for tex built-in template.
SingleCompile-2.9.1.zip 2.9.1 2011-10-06 7.0 Hong Xu Complete document related to compiler priority;
add chromium built-in template;
fix IE priority bug in the built-in template.
SingleCompile_2.9beta.zip 2.9beta 2011-09-19 7.0 Hong Xu Now compiler template contains "priority" field, and each built-in template have been set a priority; this means, when user does not choose one compiler explicitly, SingleCompile will automatically choose the compiler with the highest priority (related document is not available yet);
Add clang built-in template for Object-C;
some minor improvement of clang built-in template for C and C++.
SingleCompile.zip 2.8.9 2011-09-06 7.0 Hong Xu Improve the detection of Microsoft Visual C++ in the built-in template on Windows (Specified version of MSVC could be detected now)
** No need to upgrade to this version if you do not use Microsoft Visual C++
SingleCompile.zip 2.8.8 2011-09-03 7.0 Hong Xu When using :SCChooseCompiler, list compilers ordered alphabetically;
Add arora, epiphany built-in template for html and xhtml;
Improve the detection of IE on Windows;
Remove OS/2 supporting code since they are unable to be tested(send me an email if you have problems on this).
SingleCompile.zip 2.8.7 2011-06-26 7.0 Hong Xu Fix some python asynchronous mode availability detection problem;
Add GNAT Ada compiler built-in template.
SingleCompile.zip 2.8.6 2011-06-14 7.0 Hong Xu Add Object-C built-in template (gcc);
improve Javascript and idl built-in template.
SingleCompile.zip 2.8.5 2011-05-25 7.0 Hong Xu Add php built-in template;
Hide the console window when run asynchronously on Windows.
SingleCompile.zip 2.8.4beta 2011-05-22 7.0 Hong Xu Some message improvements for asynchronous run.
SingleCompile.zip 2.8.3beta 2011-05-21 7.0 Hong Xu Add :SCIsRunningAsync command to check whether there are background process running asynchronously;
many improvements on MS-Windows for asynchronous running;
add :SCTerminateAsync and :SCViewResultAsync commands to menu;
some minor bug fixes.
SingleCompile.zip 2.8.2beta 2011-05-16 7.0 Hong Xu Add 'auto' mode for asynchronous running;
add :SCTerminateAsync command;
some bug fixes and improvements.
SingleCompile.zip 2.8.1beta 2011-05-14 7.0 Hong Xu Make asynchronous run feature also available for interpreting language;
some minor bug fixes and improvements for async mode.
SingleCompile.zip 2.8beta 2011-05-14 7.0 Hong Xu Now compiled program could be run
asynchronously. (Currently this new feature requires vim compiled with python interface
SingleCompile.zip 2.7.3 2011-05-09 7.0 Hong Xu Fix a bug in IDL built-in template;
add pascal and erlang built-in template by Zhou Yichao;
some minor bug-fixes and improvements by Zhou Yichao.
SingleCompile.zip 2.7.2 2011-04-17 7.0 Hong Xu Fix a problem when compiling if using the deprecated way to add templates;
fix a shell determination problem;
add IDL built-in template;
SingleCompile.zip 2.7.1 2011-03-29 7.0 Hong Xu Fix redirection issues under csh and tcsh;
add option g:SingleCompile_showresultafterrun.
SingleCompile.zip 2.6 2011-03-19 7.0 Hong Xu Add option g:SingleCompile_showquickfixiferror;
fix a few bugs in the built-in template including templates for g++, clang and dosbatch.
SingleCompile.zip 2.5 2011-03-14 7.0 Hong Xu Integrate with vim's compiler feature;
add G95 and Microsoft Visual C# built-in template;
fix some minor bugs.
SingleCompile.zip 2.4.2 2011-03-07 7.0 Hong Xu Fix a bug which may cause some programs of some language, such as java, c#, may not run properly;
Add C#(mono) built-in template.
SingleCompile.zip 2.4.1 2011-03-05 7.0 Hong Xu Add g:SingleCompile_resultheight option;
add TCL language built-in template.
SingleCompile.zip 2.4beta 2011-02-08 7.0 Hong Xu Add SCViewResult command, which allows you see the output result of last run command;
if tee command is available, also use 'tee' to redirect the output result on Windows.
SingleCompile.zip 2.3.4 2011-02-07 7.0 Hong Xu Add R and zsh built-in template.
Update the document.
SingleCompile.zip 2.3.3 2011-02-01 7.0 Hong Xu Fix some problems when the source file name contains spaces.
SingleCompile.zip 2.3.2 2011-01-28 7.0 Hong Xu Add csh and tcsh built-in template;
improve sh built-in template;
gives an error message when choose a compiler/interpreter whose template is not set.
SingleCompile.zip 2.3beta 2011-01-21 7.2 Hong Xu Add out-file feature. out-file feature is a feature which will detect whether the current file requires compilation according to the last modification time of the source file and the output file.
Makes gfortran available on Windows for built-in template.
SingleCompile.zip 2.2.10 2011-01-12 7.2 Hong Xu fix a bug when showing some specific messages.
SingleCompile.zip 2.2.9 2010-12-28 7.2 Hong Xu Fix a bug when quickfix for this plugin is set to be unused.
SingleCompile.zip 2.2.8 2010-12-27 7.2 Hong Xu fix a language template bug.
SingleCompile.zip 2.2.7 2010-12-24 7.2 Hong Xu Add D language support.(Thanks, sky hi!)
Fix a bug about math.h recognization for C and C++.
SingleCompile.zip 2.2.6 2010-12-09 7.2 Hong Xu Optimize the error message when no filetype is specified when compiling;
when buffer's name is empty, gives an error message.
SingleCompile.zip 2.2.5 2010-12-02 7.2 Hong Xu Apply Darek's patch as a better solution to fix the directory switching bug;(Thanks, Darek!)
if the language template is not defined, show an error message when using ":SCChooseCompiler" command.
SingleCompile.zip 2.2.4 2010-12-02 7.2 Hong Xu still fix directory switching problem.
SingleCompile.zip 2.2 2010-11-23 7.0 Hong Xu Add "Predo", "Postdo" features;
makes template smarter(such as automatically add "-lm" flag on UNIX when using some C compilers if math.h is included);
add some new template(Haskell, etc);
improve the document;
fix some bugs.
SingleCompile.zip 1.2.1 2010-09-03 7.0 Hong Xu Fix a minor document bug.
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.