Search code examples
intellij-ideapycharm

How to count lines of code (LOC) using IntelliJ IDEA?


title says everything plus: - development language Lua - code revision control system - Perforce (integrated with IntelliJ IDE)


Solution

  • You can hack it via the native, global search:

    1. Ctrl + Shift + F (to open global search)
    2. Use regex mode (check the .* checkbox)
    3. In the searchbox, enter only a caret "^" (without the quotes)
    4. You may want to limit the search to a specific directory, via the "directory" tab
    5. Hit the "Open in Find Window" button on the bottom-right
    6. If it asks whether you want to continue, press "Continue"

    The number of lines is shown at the end of the "Found occurrences" sentence.

    Notes:

    • In regex, the caret (^) denotes the start of a line, except when inside square brackets, in which case it denotes negation
    • If you wanted to count non-empty lines, you could instead use "^.*\S" (without quotes), which signifies "The start of a line (^), followed by any number of characters (except newline) (.*), followed by a non-whitespace character (\S)"

    Gloabal search for Lines of Code