美文网首页
VS Code 配置

VS Code 配置

作者: district10 | 来源:发表于2018-05-06 23:14 被阅读292次

通用的配置

control-shift-[ 可以折叠代码,这很好,但 vim 移动到 fold 上,会自动 unfold,github 上一圈吐槽的。

不过这也解决了,需要在 user settings 里加上:

    "vim.foldfix": true,

然后就可以快乐地 fold 代码,然后移动了。

VS Code 有一些必记的快捷键(你要用的话。。。逃不掉这些操作):

  • control-p 打开文件 (输入 ?可以查帮助)
  • control-shift-p 输命令
  • F12,control-F12,跳转到定义啥的(右键可以用 context menu 看这些操作)Ubuntu 上,Fn+Escape 可以切换 Fn 默认是否打开
  • alt-n 搜索 symbol
  • control-shift-f 搜索字符串

其他的一些配置:

    "files.trimTrailingWhitespace": true,

C++ 开发的配置

首先,用 clang-format 格式化代码,安装一下:

sudo apt-get install clang-format

在工程目录下建一个 Makefile:

ALL_SRCS = $(shell git ls-files    | grep -E '\.h$$|\.cpp$$|\.hpp$$|\\.c$$' | tr '\n' ' ')
MOD_SRCS = $(shell git ls-files -m | grep -E '\.h$$|\.cpp$$|\.hpp$$|\\.c$$' | tr '\n' ' ')
 
all: lint
lint:
    @clang-format -i $(MOD_SRCS)
lint-all:
    @clang-format -i $(ALL_SRCS)
install-hook:
    echo "#!/bin/sh\nmake lint-all" > .git/hooks/pre-commit
    chmod +x .git/hooks/pre-commit

再创建 .clang-format 文件:

Language:        Cpp
# BasedOnStyle:  LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands:   true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterFunction:   true
  AfterClass:      true
  AfterControlStatement: false
  AfterEnum:       true
  AfterNamespace:  true
  AfterObjCDeclaration: false
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit:     80
CommentPragmas:  '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
  - Regex:           '^(<|"(gtest|isl|json)/)'
    Priority:        3
  - Regex:           '.*'
    Priority:        1
IndentCaseLabels: false
IndentWidth:     4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments:  true
SortIncludes:    true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles:  false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard:        Cpp11
TabWidth:        4
UseTab:          Never

然后就能在工程根目录用 make lint 格式化修改了的文件。用 make lint-all 格式化所有的代码。

还可以加一个 hook 让 git commit 的时候自动格式化。用 make install-hook

(写这几个小脚本用了我好几十分钟呢,不过以后就轻松了)

VS Code 用户,还可以安装 clang-format 插件,然后在个人设置里加上保存时自动格式化的配置。按 control-shift-p, 搜 'user settings' 打开配置,加上:

"editor.formatOnSave": true,

相关文章

  • VS Code Python运行环境配置

    安装python,VS CODE 然后,在VS CODE界面,打开“调试>>打开配置/添加配置” 其实就是配置la...

  • wsl 安装 Docker 与 Apollo

    准备工作 配置了 WSLg 安装 VS Code 在 VS Code 配置插件 Remote - WSL[http...

  • VS Code 运行html文件

    用VS Code编写html文件,想在VS Code中直接打开运行,配置如下: 配置tasks.json 打开VS...

  • VScode运行HTML文件

    用VS Code编写html文件,想在VS Code中直接打开运行,配置如下: 配置tasks.json 打开VS...

  • vscode+phpstudy2018构建php调试环境

    由于vs code开源和跨平台,而且插件很多,所以打算以后编写和调试php都用vs code。 配置vs code...

  • Python+VS Code

    参考知乎配置 一、准备 安装Python3 安装VS Code 二、配置VS Code 1. flake8和yap...

  • 2020-04-26

    VS Code的安装与配置 Visual Studio Code(VS Code)是微软旗下的一个开源文本编辑器,...

  • Flutter总结,持续更新

    起步 安装 配置编辑器VS Code

  • MAC+VS Code+Python+Markdown调试配置

    MAC+VS Code+Python+Markdown调试配置 最近,初初阶程序小白——澜子迷上了VS Code的...

  • Vue笔记

    Vue笔记 一:环境配置开发工具使用VS Code,Window使用nvm安装管理node版本。VS Code安装...

网友评论

      本文标题:VS Code 配置

      本文链接:https://www.haomeiwen.com/subject/izuprftx.html