Compiling quickly in a text editor
The problem we're trying to solve is to run the compile script
and jump to the first error message as quickly as possible.
Put this in your file
It looks like you can set the
This works best for C. If you have a makefile,
These commands are probably good enough, but if you want more, you can have it:
emacs
(To learn emacs, start emacs and run the tutorial: Ctrl-H t.)Put this in your file
~/.emacs
.
(If you don't have one already, you'll have to create one.)
(require 'cc-mode) ; automatic mode for C code (setq c-default-style '((java-mode . "java") (c-mode . "linux") ;(c++-mode . "k&r") (other . "gnu"))) (setq-default indent-tabs-mode nil) (require 'compile) ; support for compile command (setq compile-command "sh compile") (global-set-key "\C-c\C-c" 'compile) ; make C-c C-c do compile when ; not otherwise specified (defun bind-compile-key () (local-set-key "\C-c\C-c" 'compile)) (add-hook 'c-mode-hook 'bind-compile-key) ; make C-c C-c do compile ; in C modeTo compile, type
C-c C-c
; to jump to the next error,
type C-x `
.
vim
(To learn vim, try Learn Vim Progressively—and relive the 1970s with Colonel Austin.)It looks like you can set the
makeprg
variable to
./compile
and then use vim's :make
command.
See
- Seven habits of effective text editing, by Bram Moolenaar (author of vim)
- Marshall Moutenot's .vimrc files (old version here)
- Introduction to Programming in C/C++ with Vim
:make
command works,
but Constantin Berzan, who has taken 40, has this advice:This works best for C. If you have a makefile,
:make
will call make
and take you to the first error. :cc
re-displays the error in the
status bar, :cn
and :cp
go to the next and
previous errors.
To get all the gory details, try
:h
quickfix
.These commands are probably good enough, but if you want more, you can have it:
- You can set up a shortcut for
:make
, for example I havemap
as a line in my:w :make ~/.vimrc
for F9 to save and compile in one step. If you don't use makefiles, you can customizemakeprg
, for example:set makeprg=sh compile
. -
If commands are unambiguous, they can usually be shortened, e.g.
:make
==:mak
,:cclose
==:ccl
etc.