Even though I work with C/C++ projects that are not related to Qt technology, QtCreator has become my main code editor. Here I explain some of the main reasons why I prefer it over other alternatives.
I usually prefer a more “plain” editor over a full-blown IDE for programming. This is mainly because I work with embedded Linux systems, and I like to interact with the target device from terminal using for instance SSH and SCP. Usually the project and build are also handled using custom CMakeLists or Makefiles which are not tied to any particular IDE or its project file format. So for me the editor is for writing code. There are, however, some IDE features that I like to have:
- Auto-completion that works for both standard libraries and project files
- Easy navigation in large code base
For general purpose editing (scripts, git commit messages, etc.) I usually use neovim or Sublime Text. However, I feel that navigating in a large project soon becomes quite awkward in these editors. It is possible to get plugins for both of them for auto-completion, project organization and much more, but still they aren’t exactly what I want.
For me the answer is QtCreator. Both the smart C/C++ auto-completion as well as project navigation (switching between source/header, following symbol under cursor, etc.) works without a hazzle or additional plugins. Topping it all off, the vim editing mode makes it really familiar to move around and edit.
On most Linux systems, the QtCreator can usually be found with the package manager. However, it is not likely the latest version. Installer for the most recent version can be found here.
To install, add execution rights to the file and run it from terminal. Then just follow the installation instructions:
chmod u+x qt-creator-opensource-linux-x86_64-4.2.0.run
I also prefer the dark theme which can be enabled from Tools → Options → Environment → Interface tab.
Auto-complete and clang analyzer
The auto-completion in QtCreator works right out-of-the-box and it shows both standard libraries as well as symbols in the current project. It is also a real C/C++ auto-complete which suggests functions and symbols that are relevant in the current context. It is also able to show parameters and return values for suggestions. In some text editors the auto-completion just suggest all matching words in the current document or project.
Another useful feature is Clang code model. This feature parses the source files on the fly and provides similar warnings and error that are normally presented during compilation. This helps to catch errors such as typos, missing semicolons and unmatched parentheses immediately. It can also suggest fixes which are indicated using the lightbulb icon.
This feature is not enabled by default but it can easily be enabled from Help → About plugins menu.
One of my favourite features in QtCreator is the FakeVim mode. Since I already use vim for other general purpose editing, it is very convenient to be able to move around, select, yank and so on using the same key combinations. Even though the vim-mode is not very clearly visible in the editor, it is actually built into the QtCreator and works right out-of-the-box.
To enter vim-mode, just open a document and use Alt+v Alt+v key combination (the same combination is used to switch back to normal mode). This is also a great way to start learning vim, because you can always switch back easily if you need to.
The vim-mode has its own section in the settings (Tools → Options → FakeVim). Indentation settings such as tabulator size should be set to match the normal editing mode.
The vim-mode is not limited to moving around in single document. It is also possible to split the editing area using vim :split and :vsplit commands. Navigation between the splits works using Ctrl+w + h/j/k/l like in vim. To close a split, navigate to it and use :q command (Ctrl+w + q doesn’t seem to be supported).
Some of the QtCreator shortcuts are also available when the vim-mode is enabled. Especially useful commands are “Follow symbol under cursor, F2“, “Switch between function declaration/definition, Shift+F2″ and “Switch header/source, F4“.
There are also some limitations. Both the vim-mode and QtCreator have key combinations that require the control-key. If the control-key is interpreted by FakeVim (pass control key setting), QtCreator shortcuts like Ctrl+s to save do not work (in vim-mode you can save with :w command). If, in turn, the control key is passed to QtCreator, some vim key combinations are unavailable. Personally this has not been an issue for me since it is possible to do most operations with vim commands (or temporarily switch to normal mode with Alt+v Alt+v).
You are likely to also notice some other minor differences with the FakeVim and real vim (e.g. not all commands are supported). Still, the vim-like editing works well and it has been integrated smoothly to the rest of the editor. It is one of the main reasons I use this editor in my day-to-day work.
9 thoughts on “My editor of choice for C/C++: QtCreator + FakeVim”
there is a nice feature in FakeVim. do you know about that:
you just need to press ‘,’ symbol in command mdoe and then fakevim passes next shortcut to qtcreatore core without catching this up by plugin
LikeLiked by 1 person
No I was not aware of that. That makes the vim-mode even more powerful. Thanks for the tip!
I do embedded linux too – used Qt for the first time about a year ago and after awhile realized it made for a good general purpose editor/IDE. One advantage here was full auto completion which I could never get in Eclipse. The reason I became receptive to Eclipse alternatives was that scrolling problems had developed in the editor under Linux. That appears to have been fixed with Oxygen but I’m favoring qtcreator now.
QtCreator was my favorite IDE for C++ for a while too (would still be my second choice). After trying NetBeans, Eclipse, none of these IDEs seemed to work very good for C++ (it’s been a while so I can’t remember the exact shortcomings).
I gave CLion a shot and I loved it so much I just decided to buy a personal license for it. Sure you have to pay for it (around 85 first year, but then subsequent years are less) but it is updated frequently which is nice if you are using newer C++11/14 features. IMHO it’s worth the money to avoid the headaches of dealing with all the little problems other IDEs have.
I couldn’t believe there is such a gap in the IDE field for C++, I figured if anything I would have found a million different choices. In reality it’s just a dozen IDEs that are broken in one area or another. Maybe that’s why some say just use VIM or Emacs. But screw that!
LikeLiked by 1 person
I have never actually tried CLion but I think I’ll need to give it a try. That price doesn’t seem bad for something you use practically every day.
New version of QtCreator (4.6.0) was recently released (http://blog.qt.io/blog/2018/03/28/qt-creator-4-6-0-released/) and it updates the clang code model to 5.0 to introduce support for many C++17 features. It also integrates clang-tidy which now works out-of-the box and provides a lot of diagnostics. Loving it so far.
Do you know if there’s a shortcut to navigate between open documents, without having to open the documents window first? Like when navigating between tabs in a browser… Can’t find it…
LikeLiked by 1 person
You can use Ctrl+Tab to scroll through open files even if you have vim mode enabled. Though I don’t think there is a shortcut to jump directly to specific file. Another option is to use the locate menu: Ctrl+K and then type o and space and then start writing the file name.