Search and navigation in CLion

When working with large projects, it’s often beneficial to be able to quickly locate files and folders, as well as types and their members. It is also very helpful to be able to quickly visualize and navigate inheritance hierarchies as well as include dependencies. This is precisely what IDEs are made for, and CLion is no exception. Here is an overview of some of the navigation facilities that come with CLion.

Go To Actions

CLion comes with several quick navigation actions available with their respective shortcuts (given here for Windows and Linux, as well as for OS X for the cases it differs from Windows and Linux one). These include

  • Go to Class (Ctrl+N/⌘O) takes you a particular type

    Notice how you don’t need to enter the full type name – just a few letters are enough to find something. Also, it’s possible to press Ctrl+N/⌘O once again to have the search include files which are not part of the project as such.
  • Go to File Name is invoked with Ctrl+Shift+N/⇧⌘O and, as the name suggests, this takes you to a particular file.

    One thing to note is that you don’t have to use a proper substring to search on. For example, typing the letters cml will locate the CMakeLists.txt file:
  • Go to Symbol, invoked with Ctrl+Alt+Shift+N/⌥⌘O, locates a symbol, whether it is the name of a type or type member.

File Structure

One neat way of visualizing the contents of the file you are currently in is the File Structure window. This gives you a tree-like presentation of all the structures (classes, members, nested classes, etc.) in a file. CLion supports two-way synchronization, so selecting the item in the tree takes you to the corresponding place in the code, and vice versa:

You can bring up this tool window by pressing Ctrl+F12/⌘F12. Please note that it only supports structured code files.

In-Code Navigation

CLion comes with plenty of navigation options when you’ve got the cursor on a particular code element. First, there’s Navigate to Related Symbols (Ctrl+Alt+Home/^⌘↑) — this does exactly what the name suggests, meaning that if you’re on a function declaration, for example, it will take you to the definition.

CLion also has a shortcut in case you want to Navigate to Declaration (Ctrl+B/⌘B). You can also Navigate to Super Definition to jump up the inheritance hierarchy.

Hierarchy Windows

Another useful tool window is the Type Hierarchy window, which shows an inheritance hierarchy for a particular type:

This hierarchy window can be shown with Ctrl+H, and can show either all the descendants or all the parents (which is helpful when multiple inheritance is concerned).

Another type of hierarchy that CLion knows how to illustrate is the Imports Hierarchy (Alt+Shift+H), usable for quickly browsing the chain of includes that a particular header file brings.

Yet another type of hierarchy window is the Caller/Callee Hierarchy (Ctrl+Alt+H), which illustrates who exactly calls a particular function. The hierarchy illustrates all the call chains as a tree that you can navigate:

Recent Files and the Switcher

To navigate to any of the currently open files in the solution, simply press Ctrl+Tab. Similarly, to navigate to any of the recent files you’ve been working with, press Ctrl+E/⌘E. Both of these windows use the Switcher mechanism:

Note the elements on the left: selecting them will open up the corresponding tool window. The entire list can be scrolled forwards and backwards with Tab and Shift+Tab.

Error Navigation

To quickly go through the errors in a project, you can press F2 to Go to Next Highlighted Error, and Shift+F2 to go back.

Watch CLion search and navigation features in action:

If you haven’t seen CLion already, grab the EAP build and give it a go! ■

This entry was posted in Tips'n'Tricks and tagged , . Bookmark the permalink.

8 Responses to Search and navigation in CLion

  1. Andy Aylward says:

    This is very exciting! I’m thrilled about you folks making a c++ IDE!

  2. I find this whole series of tips and tricks invaluable. I use CLion and PyCharm, and every time I read one of your articles I find out some little time-saving feature I didn’t know about.

  3. Oaheix says:

    Thanks very much for the helpful tips and tricks! But I have one simple question: When I navigate through a complex code hierarchy, and go deeply into some position, is there a way to go back to the previous cursor positions, i.e. to go back along the history line, during the code navigation?

  4. Alexey says:

    “File Structure…CLion supports two-way synchronization, so selecting the item in the tree takes you to the corresponding place in the code, and vice versa:”

    This is not true about “vice versa support”. “File Structure” tool window does not support “Autoscroll from source”. There are not setting items “Autoscroll to source, Autoscroll from source” for “File Structure” tool window.
    It this is a pity. WebStorm seems also does not have this useful capability.

    I thought to create request feature for this, but it seems I should create bug report.

Leave a Reply

Your email address will not be published. Required fields are marked *