CLion 2017.2 Help

Rename Refactorings

In this section:

Basics

Rename refactorings allow you to rename with all the references to them in the code corrected automatically.

    Examples

    Renaming a symbol

    To rename a symbol, follow these general steps

    1. Select the item to be renamed.
      • To select a file, click the desired file in the Project Tool Window.
      • To select a symbol in the editor, place the caret at the name of the symbol to be renamed.
      • To select a symbol in the Project Tool Window, make sure that the members are shown, and then click the desired symbol.
      • To select a symbol in the Structure view, click the desired symbol in the Structure tool window.
    2. Choose Refactor | Rename on the main menu or on the context menu, or press Shift+F6.
    3. The suggested name appears right below the symbol in question. You can either accept suggestion, or type a new name.

      cl rename

    4. If CLion detects the symbol occurrences in comments and strings, it suggests to extend refactoring to that usages as well:
      cl renameStrings
      In this case:
      • Choose Show Usages to view that usages in Find Tool Window.
      • Choose Rename Only Code Usages to apply refactoring to code usages only.
      • Choose Rename All Usages to rename both code and non-code usages.
      • Click Cancel to terminate and return back.
    5. Apply changes.

    Renaming a file or directory

    To rename a file or directory

    1. Select a desired file in the Project tool window.
    2. Choose Refactor | Rename on the main or context menu or press Shift+F6.
    3. In Rename File dialog box that opens, specify the new file name. Select Search in comments and strings checkbox to let CLion apply changes to comments and strings.
      cl renameFile
    4. Press Preview to observe possible changes in Find Tool Window. Press Refactor to proceed.

      CLion finds all the occurrences of the file name and changes them respectively.

    Example

    This example represents CMakelists.txt before and after Rename file refactoring:

    BeforeAfter
    cmake_minimum_required(VERSION 3.2) project(Calendar_master) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES calendars/Calendar.cpp calendars/Calendar.h main.cpp) add_executable(Calendar_master ${SOURCE_FILES}
    cmake_minimum_required(VERSION 3.2) project(Calendar_master) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES calendars/CalendarRen.cpp calendars/CalendarRen.h main.cpp) add_executable(Calendar_master ${SOURCE_FILES})

    Important notes

    Last modified: 15 December 2017

    See Also

    External Links: