Eclipse

CPP大法好         删IDE保平安
人在做,天在看      垃圾索引留祸害
Eclipse弟子说真相   教你编程莫拒绝😄
  • clion?(2017.3)
    • 仅支持cmake项目
    • indexer工作慢而且有点问题
    • 多个project不能放在同一个窗口
    • format code的结果和clang-format不一样
  • vscode? (1.28)
    • 他的index只做到了function name的匹配,做不到function signature的匹配

Eclipse CDT(2019-06)

虽然自动补全让人尴尬,但它还是很不错的。

Eclipse Plugin

Plugin List 下面加黑的两个强烈建议安装上。

  • Cppstyle(检查代码

    可以在每次保存代码的时候利用cpplint.py和clang-format格式化代码和检查代码风格,

    安装之后需要在(Preference -> C/C++ -> CppStyle)配置clang-format和cpplint.py的位置

    同时在(Preference -> C/C++ -> Code Style -> Formater): Code Formatter改成Cppstyle

  • Quick Search(全文检索

  • Vrapper(vim扩展

  • Cmake Editor

  • Bash Editor

Eclipse初始化

  • General-> startup and shutdown 除了Codan Analysis UI for C/C++ 全都可以关了,加快启动速度

  • C/C++-> Code Style-> Formatter-> Activate profile导入eclipse-cpp-google-style.xml

  • 把Copyright加到文件模版里面

    C/C++-> Code Style-> Code Template-> Comments-> Files

      ////////////////////////////////////////////////////////////////////////////////
      // Copyright 2016, Oushu Inc.
      // All rights reserved.
      //
      // Author:
      ////////////////////////////////////////////////////////////////////////////////
    
  • General-> Editors-> Test Editors-> Quick Diff(这个影响你在右边的边栏看见的东西)

    [✔]Enable quick diff

    [✔]Show difference in overview ruler

    Use this reference source: A Git Version

  • General-> Editors-> Text Editors

    [✔]Show print margin [80]

    [✔]Show whitespace charactor

  • Link with editor(Project explorer, Outline, History)(那个左右两个箭头的按钮)

  • C/C++-> Indexer-> Allow heuristic resolution关掉

  • C/C++-> Editor-> Scalability-> 全都关掉,number of lines is more than调大成10000

  • General-> Keys给content assist绑定一个快捷键,例如⌃P(vim的补全键是这个)

Eclipse常用操作

  • 导入项目(可以在一个workspace里面导入多个project,让代码索引跨越多个project)

    • File-> New-> Makefile Project with Existing Code

    • 记得选OSX Toolchain

    • 配置project的Paths和Symbols让indexer运行起来,你的Eclipse除了语法错误应该没有任何红线

      • 先去了解一下gcc -I/opt/dependency/package/include啥意思

      • Project-> Property-> Preprocessor Include Paths, Macros etc.-> Entries

        GNU C++-> CDT User Setting Entries-> Add…

        • Preprocessor Macro

          Name: __cplusplus Value: 201103L

          [✔]Treat as built-in

      • Project-> Property-> C/C++ General-> Paths and Symbols-> Import settings

  • 格式化代码/格式化某段代码⌘⇧F

  • Refactor

    • 修改符号(函数、变量、类)名⌘⌥R
    • 修改文件名F2
  • Git

    我都绑了⌃⌥G做快捷键

    • 在editor中右键,Team-> show revision information(相当于git annotate

      想看看某段代码是谁写的,这段代码是哪些改动一块进来的

    • 在editor中右键,Team-> show history(相当于git log

      想看看谁改过这个文件

  • Tasks

    • TODO

      将来要做的事情

    • FIXME

      是一个bug,但是没有测到

    • XXX

      现在没有功能问题,但是有更好的做法或者以后可能会有问题

Eclipse Navigate

  • 我想找某个符号或者文件(所有源文件

    • Open Element ⌘⇧T
    • Open Resource ⌘⇧R
  • 我想在同一个文件里头跳来跳去(单个文件内

    • Quick Outline ⌘O
    • Go Line ⌘L
  • 我想在鼠标待过地方跳来跳去(编辑位置

    • Back ⌘[
    • Forward ⌘]
  • 我的光标现在指向了一个符号(函数、变量、类)

    • 我想看哪里用到现在光标指向的这个符号

      • Open Call Hierarchy ⌃⌥H

      • Reference ⌘⇧G

        search view中Hide read-only reference去查找修改的地方

    • 我想看现在光标指向的这个符号的声明和实现

      • Open Declaration F3
    • 我想看现在光标指向的这个符号在哪里被继承,在哪里被重载了

      • Open Type Hierarchy F4
  • 我想看当前编辑的这个文件的include情况(头文件和源文件

    • Open Include Browser ⌘⌥I
    • Toggle Source/Header ⌃⇥
  • 我想找一段文本

    • Quick Search的⌘⇧L(这个东西得自己安一下,eclipse自带的search不是很好用

      找log信息的出处,找testcase

FAQ

  • Index对不上了

    Project-> C/C++ Index-> Rebuild