2013-12-11

Fast Compilation and Execution of Source Code

Possible software: Vim.

Why?

In a heavy IDE, you need to click a button or some keyboard shortcuts. Unless you frequently use the keystrokes, you'll likely forget them since they are usually non-transferable IT skills.
It's different in Vim. Since it's an F/OSS programmable editor, you can add whatever plugins and extra functions you like. You can adjust you .vimrc file so that the editing environment won't have too many undesirable changes.
Vim is lightweight. If your computer collapses (or even gives you the notorious BoD before RiP) due to loading IDE, Vim is your choice since it may still work with some good design and functions.
What are the good things?
  1. Diminished role of mouse and more use of keyboard due to modes
  2. Syntax highlighting and file type detection
  3. and more from my previous blog post

How? (Doesn't need c.vim)

  1. Set up makefile (simple tutorial about makefile)
  2. Run :make
  3. Run :!./%< on *nix (or simply :!%< on M$ Win*) [1]
Notes:
  1. set makeprg=mingw32-make in vimrc for MinGW make (more details about makeprg)
  2. % stands for the current file, and < stands for the file name without extension.
Advantages:
  • In the whole process, you don't have to leave Vim and keyboard.
  • The commands are the same whatever your files are (already determined by makefile), so you don't waste time to think and type in the correct name.
2 quotes from Sharpe (I don't remember the exact wordings):
"The battle is not in the hands of who give the most shots. It should be those who shot the best."
"A good soldier can fire 3-4 rounds a minute."
My sample makefile:
hello : hello.c
    gcc -o hello hello.c
clean:
    rm -f hello
Note: Insert tabs for indentation, not whitespaces.
If the compiled program is hello.exe, perhaps the extension name is also needed for rm. (I have never tested it.)

With c.vim

Follow the menu and you'll be also good.

Reference:
[1]: How do I run a C program from Vim?

No comments:

Post a Comment