Use Vim's Quickfix List to Compile Code and Jump to Errors
Run builds from Vim, parse compiler errors into the quickfix list, and jump to faulty lines without leaving the editor.
01 Apr 2026, 12:11 UTC

The problem and the useful takeaway
Problem: you compile code in a terminal, copy the file path and line number from an error message, switch back to Vim, and reopen the file at the right line. Takeaway: Vim can run the build, parse compiler output into a quickfix list, and let you jump between errors with :cn and :cp without leaving the editor.
Prerequisites
Inside Vim, run:
:version
Look for +quickfix in the feature list. If you see -quickfix, your Vim build lacks quickfix support; install a fuller Vim package or build Vim with the quickfix feature before continuing. This check does not change any files.
You also need a build tool on your shell PATH, commonly make or a compiler such as gcc, plus a source file to build.
Configure the build command and error parser
Vim runs builds with :make, which executes the makeprc option through the shell. It then parses the command output using errorformat, a pattern that identifies the file name, line number, column, and message on each error line.
Where to run: Vim normal mode. Required permissions: none to set options in the current session; write permission to a source file only if you create the example file. Placeholder: %:r expands to the current file name without its extension.
Example for compiling a single C file with GCC:
:set makeprc=gcc\ -Wall\ -o\ %:r\ %
:set errorformat=%A%f:%l:%c:\ %m,%-G%.%#
| Placeholder | Meaning |
|---|---|
%f | File name |
%l | Line number |
%c | Column number |
%m | Error or warning message |
The %-G%.%# part tells Vim to ignore lines that do not match the primary pattern. Adjust errorformat to match your compiler's actual output; an incorrect pattern produces an empty quickfix list or maps errors to the wrong file and line.
Risk: makeprc values containing shell metacharacters such as spaces, semicolons, or redirections must be escaped carefully, because Vim passes the string to the shell.
Run the build and open the quickfix window
Run:
:make
Vim executes the build synchronously, so the editor blocks until the command finishes. When it completes, open the list:
:copen
Expected check: the quickfix window shows one entry per parsed error or warning, including the file name and line number. Pressing Enter on an entry opens that file at the reported line.
Navigate between errors
:cn— jump to the next error.:cp— jump to the previous error.:cc {nr}— jump to quickfix entry number{nr}; for example,:cc 2opens the second entry.:cfirstand:clast— jump to the first or last entry.:cclose— close the quickfix window.
These commands work within the current Vim session; you do not need to switch to a terminal or reopen files manually.
Practical verification with a scratch file
Create a scratch source file, for example scratch.c, containing a deliberate syntax error. Set makeprc to your compiler command as shown above, then run :make followed by :copen. You should see the scratch file and the faulty line listed in the quickfix window. Press Enter on that entry and confirm Vim opens scratch.c at the reported line. Add a second intentional error and confirm that :cn and :cp move between the two entries without leaving the editor.
If the quickfix list is empty after :make, run the same compiler command in your shell and compare its raw output to your errorformat pattern. The file, line, column, and message fields must line up.
Reset and recovery
Changing makeprc or errorformat alters Vim's session state but does not modify files on disk. To reset an option to its default, use :set option&. To clear the quickfix list without restarting:
:cexpr {}
Close the quickfix window with :cclose. Because :make only runs a build command, it does not edit your source files, so there is no file-level rollback; undo buffer edits with u only if you manually changed code during this session.
Limitations
:makeblocks Vim until the build finishes by default.- The quickfix list exists for the current Vim session and depends on the configured
errorformat. - Compilers with unusual output formats require a custom
errorformat; no universal pattern fits every tool.
Practical result check: after :copen, each quickfix entry should open its source file at the correct line when you press Enter. If it does not, revisit errorformat before relying on :cn and :cp for navigation.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.