4

实用刷题、线上赛C++配置(VSCode + ccls)

 2 years ago
source link: https://h-cheung.gitlab.io/post/%E5%AE%9E%E7%94%A8%E5%88%B7%E9%A2%98%E7%BA%BF%E4%B8%8A%E8%B5%9Bc++%E9%85%8D%E7%BD%AEvscode-+-ccls/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

写不动题了,来写篇小文章放松一下,记录一下自己的配置,也供读者参考。

注:运行环境为Arch Linux

需要安装的包

  • gcc 如果不用pbds等,可以直接用clang编译,和gcc的差异基本上只有少量UB,__int128也是支持的,不过Linux基本上不能不装gcc
  • llvm(clang) 除了作为一个编译器之外,还提供强大的自动补全、代码检查、代码格式化等相关工具,clion、qtcreator等都依赖它
  • ccls 基于clang的LSP(language server protocol),完成度比clang的类似组件clangd更高。注意:更新clang后需要用新版本的clang重新编译ccls,否则可能会出现各种问题(包括完全挂掉)
  • visual-studio-code 体验不错,插件生态非常好的编辑器
  • ccls 核心插件,提供语法检查、补全、高亮、变量重命名、code lens等等
  • clang-format ccls的提供的格式化偶尔会抽风,单独用这个比较稳定
  • Code Runner 一键编译运行
  • easy-snippet 非常方便的snippet管理工具,可以用来存板子
  • CodeLLDB 可选,整合lldb,偏好gdb的用户可以不装
  • Vim 可选,vim模拟
  • ICIE 拉取codeforces上面的题目和样例,并根据通用模板生成文件,并且可以一键测试,通过后直接submit,现在已经支持直接拉取正在进行或即将进行的比赛,除了hack和看榜之外可以不用打开浏览器
  • Better Online Judge 和前者类似,用于vjudge上的比赛,功能较弱,拉取不了样例
  • vscode-clangd 备用,比如在睡前更新clang后忘记重编译ccls,第二天开始打了发现ccls炸了,可以把clangd拉出来救急(亲身经历)。目前它的功能略弱于ccls,但毕竟是llvm官方的组件,不排除以后会赶超

注:如果使用第三方调试工具的话,不用安装微软官方的cpptools插件

建议修改的设置

ccls

可以调整自动补全的case sensitivity(大小写敏感)和detailed label(补全时显示标准库函数的详细功能)。高亮部分可以根据自己喜好调整,建议打开type aliases等

Code Runner

可以自己改运行命令,以下供参考:

"c": "cd $dir && gcc -g $fileName -o /tmp/ctest && time /tmp/ctest",
"cpp": "cd $dir && g++ -g $fileName -o /tmp/cpptest && time /tmp/cpptest",

Vim

VSCode的vim插件功能挺多的,尤其是支持neovim做后端,以下设置供参考

"vim.easymotion": true,
"vim.enableNeovim": true,
"vim.sneak": true,
"vim.sneakUseIgnorecaseAndSmartcase": true,
"vim.statusBarColorControl": true,
"vim.autoSwitchInputMethod.enable": true,
"vim.autoSwitchInputMethod.defaultIM": "1",
"vim.autoSwitchInputMethod.obtainIMCmd": "/usr/bin/fcitx-remote",
"vim.autoSwitchInputMethod.switchIMCmd": "/usr/bin/fcitx-remote -t {im}",
"vim.foldfix": true,
"vim.neovimPath": "/usr/bin/nvim",
"vim.useSystemClipboard": true,

ICIE

"icie.template.list"下写你的通用模板的文件路径

Better Online Judge

这个插件的通用模板是硬编码的,直接修改~/.vscode/extensions/yiyangxu.better-oj-<版本号>/out/utils/template.js


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK