IDE

1 Clion

1.1 linux

有两种 linux 远程方式,包含编译的 Full remote mode 和仅调试 Remote debug 模式

  • Full 模式涉及编译因此要写 CMakeLists.txt
  • Full 模式要在 Deployment 选择 mounted folder,否则每次都要用 SFTP 上传源码,要配置 Folder 和 Mappings
    • cmake 设置选项 -v -- -j 3 打印具体的编译命令
  • Debug 模式只需要添加一个配置,指定执行文件的目录,设置 Path mappings。用 Remote GDB Server 或 Remote Debug 都可以

1.1.1 相关问题

  • clangd 内存占用过多,限制成 500MB,Clion clangd, how to limit memory usage
  • 堆内存占用过多和其它性能问题,Help | Change Memory Settings 改成 1000MB
  • cmake 输出引号乱码,参考这个将 Default encoding 改为 UTF-8,Settings / Preferences | Editor | General | Console_ settings
  • 要出现点击函数后卡在 “Resolving References” 上,把 Use navigation via clangd 关了
  • ubuntu 20.04 remote debug 开启 sudo 运行后无法 debug(18.04 没这个问题,gdb 版本?),程序退出 CPP-23810CPP-25441。暂时通过开始 ssh 的 root 登录绕过
  • pretty printers 设置失败 中 Andrew Brownsword 的回答
    • 把 Windows clion 下的 bin\gdb\renderers 拷到 linux
    • 打开 #com.jetbrains.cidr.execution.debugger 调试,找到 idea.log 中的 WARN python import sys ... sys.path.insert(0, ... 开始的这一行,改为 renders 路径,如 sys.path.insert(0, "/home/zack/code/install/renderers")。把整个这一行加到 linux 的 gdbinit 文件中,路径在 ~/.gdbinit 或系统配置 /etc/gdb/gdbinit
  • 设置断点后 printf 没有输出,解决方法 是在程序开始处添加 setbuf(stdout, 0);

2 Keil

3 QT

参考 从清华镜像下载在线安装工具,QT 账号登录,自定义安装,按参考中截图选择

4 VSCode

  • 解压缩 zip 后,创建 data 文件夹,开启 portable mode
  • liveserver 提升端口占用,因为防火墙没放开
  • 下载 gtags,将 bin 路径添加到系统环境变量,要重启
  • 要是工程大为了快速查引用,则关 C/C++ 扩展,开启 C/C++ GNU Global 扩展,扩展选择参考

4.1 快捷键

ctrl+k, ctrl+s 查看、设置快捷键
ctrl + o 当前符号
ctrl + shift + o 模糊全局符号搜索
alt + t 全局符号搜索
alt + f 文件
F1 / ctrl + shift + p 配置命令
ctrl + shift + f8 / shift + f8 高亮

4.2 自定义编译

  • 比如 cool 的编译和运行添加两个 task,一个属于 build group,一个是 test。示例 json 如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    {
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
    {
    "label": "编译当前目录",
    "type": "shell",
    "command": "coolc",
    "args": [
    "${fileDirname}/*.cl", "-o", "${fileDirname}/${fileBasenameNoExtension}.s"
    ],
    "problemMatcher": [],
    "group": {
    "kind": "build",
    "isDefault": true
    }
    },
    {
    "label": "spim 运行",
    "type": "shell",
    "command": "spim",
    "args": [
    "${fileDirname}/${fileBasenameNoExtension}.s"
    ],
    "problemMatcher": [],
    "group": {
    "kind": "test",
    "isDefault": true
    }
    }
    ]
    }

4.3 远程开发

  • 参考官方文档 设置要连接的设备,连上后要设置远程设备的代理的话(如安装插件),在设置的 remote 中 ,设置好后重连
    • 其它如编译和调试都和本地一样,由 3 个文件管理,看介绍视频更快上手
      • tasks.json (compiler build settings)
      • launch.json (debugger settings)
      • c_cpp_properties.json (compiler path and IntelliSense settings)
  • 免密码验证,生成 rsa key,C:\Users\XXX\.ssh\config 文件增加一行 IdentityFile C:\Users\XXX\.ssh\id_rsa 并把私钥拷贝到这里,公钥放在远程设备的 ~/.ssh/authorized_keys 中(没有新建、有则追加)
  • 对于改本地 mount 的驱动器,远程执行编译命令的情况,可用 SSH FSssh-shell task
    • host 指定用的配置文件,workingDirectory 指定目录,command 远程执行的命令,注意只打印 stderr 没有 stdout,可 redirect stdout to stderr
    • "command": "bash -c \"/usr/class/cs143/cool/bin/coolc ${fileBasenameNoExtension}.cl -o ${fileBasenameNoExtension}.s && printf '\nCompile Success!\n' \" ",

5 VIM

5.1 安装

  • 源码编译方法可以重新查找,目前参考 Building-Vim-from-source,要额外开启 clipboard 和 xterm_clipboard 特性编译时加 –with-x , 参考

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    ./configure --with-features=huge \
    --enable-multibyte \
    --enable-rubyinterp=yes \
    --enable-pythoninterp=yes \
    --enable-python3interp=yes \
    --with-python3-config-dir=/usr/lib/python3.7/config \
    --enable-perlinterp=yes \
    --enable-luainterp=yes \
    --enable-gui=gtk2 \
    --enable-cscope \
    --with-x \
    --prefix=/usr/local
    make VIMRUNTIMEDIR=/usr/local/share/vim/vim81 -j8
    # 使用 checkinstall 安装
    sudo checkinstall
    # 替换默认 vi
    update-alternatives --display vi
    sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 51 --slave /usr/share/man/man1/vi.1.gz vi.1.gz /usr/local/share/man/man1/vim.1.gz
    # 卸载
    dpkg -r vim
  • 也可 apt 安装 vim-gome,安装前确定一下版本是 vim8

5.2 TAG 数据库

5.2.1 内核 tag 生成

tag 生成参考 内核代码生成tagcscope 大型项目用法

参考第一篇使用 make O=. ARCH=arm SUBARCH=exynos COMPILED_SOURCE=1 cscope tags 生成

后续考虑能否生成 gtags 数据库

5.2.2 universal-ctags

ubuntu 自带的 ctag 版本太老,源码安装参考 Ubuntu16.04安装配置和使用 universal-ctags

5.2.3 GTags

下载源码编译安装 Vim 8 中 C/C++ 符号索引:GTags 篇LeaderF 支持 GTags

对于需要跳过的目录 修改配置文件 ,参考 man gtags,如 /src_comm/lib/:,然后在 vimrc 中设置 let g:Lf_Gtagsconf = '/home/xxx/.vim/gtags.conf'

5.3 配置

按键 内容
F2 paste toggle
F3 set list toggle
F4 highlight toggle
tab insert 切换到 normal
leader + leader noraml 切换窗口
c - k / c - j 上下滚动,set scroll=5
leader + q 关闭窗口
leader + w 删除 buffer
leader + e [except]删除自己以外的 buffer
leader + r 查找存在定义的引用,不存在定义输命令查
leader + t [tag] 全局 tag
leader + o 打开查找结果窗口
leader + p 上一条结果
leader + a [alternative buffer] buffer 切换
leader + s [search]查询字符串
leader + d 查询定义
leader + f [file] 搜索文件
leader + g [tag] 本地 tag
leader + j [j 与文件 f 键位对应] 最近打开文件
leader + l [list] 显示 tag 列表
leader + b [buffer] 搜索buffer
leader + n 下一条结果
leader + m [max]只留下当前窗口
leader + 1-9 buffer 切换
插件名称 介绍
LeaderF 文件、符号、buffer 模糊查找,需要 python 支持
执行 install.sh 提高速度
tagbar 使用 ctag 动态解析 buffer 的 tag,形成 tag 列表,配合 airline 在状态栏显示
vim-airline 状态栏美化,还带很多插件,tabline 用于 buffer 和 tab 管理。需要的字体在 vi.assets 文件夹里,配置 securecrt 即可
vim-airline-themes airline 主题
vim-dirvish 模仿 netrw 不占用侧边栏的文件管理方式,使用当前窗口打开文件
asyncrun 异步执行 shell 命令,输出到 quickfix
BufOnly 关闭除当前外其它 buffer

插件以 help 文档及 github 页面为主,其次看别人的典型用法,英文优先。不排除某些插件的功能就是不完善的可能,因此为了将 vi 用的更好,我认为学习编写插件是必须的。vi 的配置与插件以精简和全面熟悉为原则,只选择少数成熟的插件

5.4 配置备份

optionally-loaded 的插件需要把 start 文件夹替换为 opt,相关 vim-packagesUsing git-submodules to version-control Vim plugins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 配置放到 .vim
cd
mv .vimrc .vim/vimrc
ln -s .vim/vimrc .vimrc
cd .vim
git init

# 安装插件
git submodule init
git submodule add https://github.com/vim-airline/vim-airline.git pack/plugins/start/vim-airline
# 安装完后可能需要生成 help tag
:helptags ALL
# 备份到远端
git commit -m "Initial commit."

# 还原
git clone --recurse-submodules -j8 git://github.com/foo/bar.git
# 或只还原、更新插件
git submodule update --init --recursive --remote
# git checkout 时也更新 submodule 的内容
git submodule update --recursive
git checkout master --recurse-submodules
git commit

# 删除插件
git submodule deinit pack/plugins/start/vim-airline
git rm pack/plugins/start/vim-airline
rm -Rf pack/plugins/start/vim-airline
git commit

5.5 修改别人的插件

  1. 在 submodule 中新建 branch,并添加自己的 remote。目前使用的是和 vim 配置备份相同的 repo,分支名称以插件名称命名

  2. 基于这个 branch 修改,并 push -u

  3. 更新插件的 url 和 branch 为自己的,这样 git push 就可以将插件修改推送到自己的 repo 来备份

    1
    2
    3
    4
    5
    6
    7
    8
    # 参考 https://stackoverflow.com/questions/913701/how-to-change-the-remote-repository-for-a-git-submodule
    # 列出目前的
    git config --file=.gitmodules -l
    # 改 .gitmodules
    git config --file=.gitmodules submodule.pack/plugins/start/BufOnly.vim.url git@github.com:Jianfeng-Du/vim-config.git
    git config --file=.gitmodules submodule.pack/plugins/start/BufOnly.vim.branch BufOnly
    # 更新 .git 和 submodule 文件夹中的 config
    git submodule sync
  4. 要更新远端的修改,就要切换到原来的 branch pull,然后再把这个 branch merge 到自己修改的 branch 中,然后 push 到自己的 repo。更新了插件需要分别在 submodule 和 主目录提交也可以。git push --recurse-submodules=checkgit push --recurse-submodules=on-demand

5.6 操作技巧

5.7 下一步

  • vi 操作有个闯关游戏可以不断练习,vi 的优势自然是使用键盘,所以打算练习盲打
  • 学习编写插件,进一步精简插件

5.7.1 相关内容

5.7.2 系统学习