Compiling and finding errors with as few keystrokes as possible

The problem we're trying to solve is to run the compile script and jump to the first error message as quickly as possible.


(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 mode
To compile, type C-c C-c; to jump to the next error, type C-x `.


(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

It's not obvious to me just how the :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:


The best information I have about gedit seems to involve using the mouse; see Use the mouse? While you're at it, why not wear a ball and chain?
Last Modified 14 January 2013