📅 2015-Mar-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cmake, make, quickfix, vim ⬩ 📚 Archive
The Quickfix feature of Vim is great if you work regularly with source code of languages which need to be compiled, like C or C++. If you are coming from Visual Studio or Eclipse CDT, the Quickfix feature basically gives an IDE-like feel of the edit-compile-fix cycle. (The only missing piece is a visual debugger inside Vim.) For example, you can view the errors and warnings produced on compiling your code in the Quickfix window, jump to the location of the error or warning, fix them and compile the code again. All from within Vim! 😊
Here are some pointers on how I use Quickfix:
Quickfix is a plugin that ships with Vim. So, there is nothing to install!
If you have a compile command, then redirect its output to a file. Use the
-q option of Vim to open this file and you can navigate the errors from there (as described later below). For example:
$ g++ main.cpp 2> errors.txt $ vim -q errors.txt
If you are using CMake or Make, then life is much easier for you. Open Vim in
build directory and invoke make from within it using the command
:make. This runs Make and fills up the Quickfix buffer with the error output.
To open the Quickfix window, use the command
:copen. In the screenshot above, the Quickfix window is visible at the bottom.
Navigate the Quickfix window as usual and press
Enter on any error or warning line. That file, which may not even be in the same directory, is opened in the top window and the cursor is placed at the line and column of the error. Now, is that not like an IDE! 😊
Now you can jump between the editor window and Quickfix window, using the usual
Ctrl + w + w command and fix all the errors.
Once done, you can compile again right from inside Vim using
:make. More errors? Fix them. And the edit-compile-edit cycle continues 😊
For more help on Quickfix, see
Tried with: Vim 7.4 and Ubuntu 14.04