当前位置: 首页 > news >正文

【随手记】vscode中C语言满足KR风格的方法

由于生产需求,需要将编码风格改为K&R,为了方便,决定直接去修改vscode来满足

主要需要修改如下两个文件 settings.json 和 c.json

#settings.json
{"workbench.settings.applyToAllProfiles": ["C_Cpp.suggestSnippets","editor.snippetSuggestions"],"[c]": {"editor.snippetSuggestions": "top"},"C_Cpp.suggestSnippets": false
}
#c.json
{// ===== 基础控制结构 ====="K&R if": {"prefix": "if","body": ["if (${1:condition}) {","\t${0}","}"],"description": "K&R style if statement"},"K&R if-else": {"prefix": "ifelse","body": ["if (${1:condition}) {","\t${2}","} else {","\t${0}","}"],"description": "K&R style if-else"},"K&R multi if-else if": {"prefix": "ifelif","body": ["if (${1:condition1}) {","\t${2}","} else if (${3:condition2}) {","\t${4}","} else {","\t${0}","}"],"description": "K&R style multi-condition if-else if"},"K&R for loop": {"prefix": "for","body": ["for (${1:int i = 0}; ${2:i < N}; ${3:i++}) {","\t${0}","}"],"description": "K&R style for loop"},"K&R while loop": {"prefix": "while","body": ["while (${1:condition}) {","\t${0}","}"],"description": "K&R style while loop"},"K&R do-while": {"prefix": "do","body": ["do {","\t${0}","} while (${1:condition});"],"description": "K&R style do-while loop"},"K&R switch": {"prefix": "switch","body": ["switch (${1:variable}) {","\tcase ${2:value}:","\t\t${3}","\t\tbreak;","\t","\tdefault:","\t\t${0}","}"],"description": "K&R style switch statement"},// ===== 函数定义 ====="K&R function": {"prefix": "func","body": ["${1:void} ${2:function_name}(${3}) {","\t${0}","}"],"description": "K&R style function definition"},"K&R main function": {"prefix": "main","body": ["int main(int argc, char *argv[]) {","\t${0}","\treturn 0;","}"],"description": "K&R style main function"},// ===== 复合结构 ====="K&R struct": {"prefix": "struct","body": ["struct ${1:name} {","\t${0}","};"],"description": "K&R style struct definition"},"K&R typedef struct": {"prefix": "tstruct","body": ["typedef struct {","\t${0}","} ${1:name};"],"description": "K&R style typedef struct"},"K&R enum": {"prefix": "enum","body": ["enum ${1:name} {","\t${2:FIRST},","\t${3:SECOND},","\t${0}","};"],"description": "K&R style enum definition"},// ===== 错误处理 ====="K&R error check": {"prefix": "check","body": ["if (${1:error_condition}) {","\t${2:/* Handle error */}","\t${0}","}"],"description": "K&R style error checking"},"K&R return error": {"prefix": "returnerr","body": ["if (${1:error_condition}) {","\treturn ${2:error_code};","}"],"description": "K&R style return on error"},// ===== 内存管理 ====="K&R malloc": {"prefix": "malloc","body": ["${1:type} *${2:ptr} = malloc(sizeof(${1}) * ${3:count});","if (${2} == NULL) {","\t${4:/* Handle allocation error */}","\t${0}","}"],"description": "K&R style malloc with error check"},// ===== 文件操作 ====="K&R file open": {"prefix": "fopen","body": ["FILE *${1:fp} = fopen(${2:\"filename\"}, ${3:\"r\"});","if (${1} == NULL) {","\tperror(\"Error opening file\");","\t${0}","}"],"description": "K&R style file open with error check"},// ===== 其他常用结构 ====="K&R ternary": {"prefix": "tern","body": ["(${1:condition}) ? ${2:true_value} : ${3:false_value}"],"description": "K&R style ternary operator"},"K&R function pointer": {"prefix": "fptr","body": ["${1:return_type} (*${2:func_ptr})(${3:params}) = ${4:function};"],"description": "K&R style function pointer"}
}

效果如下:
请添加图片描述

http://www.dtcms.com/a/365849.html

相关文章:

  • Elasticsearch核心数据类型
  • 深度学习——卷积神经网络
  • AI产品经理面试宝典第84天:RAG系统架构设计与优化策略面试指南
  • 分布式AI算力系统番外篇-----超体的现世《星核》
  • 【Doris入门】Doris数据表模型使用指南:核心注意事项与实践
  • 从PkiAsn1Decode函数到ASN1Dec_SignedDataWithBlobs函数
  • 中山AI搜索优化实践:技术干货解析与金拓智能案例
  • select, poll, epoll
  • 【108】基于51单片机智能输液监测系统【Proteus仿真+Keil程序+报告+原理图】
  • 详尽 | Deeplabv3+结构理解
  • CSS中使用 HSL(Hue, Saturation, Lightness) 动态生成色值
  • 二叉树结尾——销毁,层序遍历与判断完全二叉树
  • python如何解决html格式不规范问题
  • windows系统服务器测试部署springboot+vue+mysql项目
  • 使用 Acme.sh 获取和管理免费 SSL 证书
  • vue2头部布局示例
  • Anaconda3出现Fatal error in launcher: Unable to create process using.....问题
  • python 连接数据库进行文件查重(SAP版本)
  • RoPE位置编码缩放因子的最优解:频率维度与位置敏感度的精妙权衡
  • TypeScript:Promise的详细用法讲解
  • 面试复习题--kotlin的设计模式
  • shell内置命令
  • UART更好的封装 添加容错代码
  • Qt6用Chart模块做数据可视化?别再用老套路,看看这套35张图背后的秘密
  • [密码学实战](GBT 15843.2-2017)Java实现基于SM4的实体鉴别机制(四十八)
  • MinIO祭了,RustFS来了!
  • 关于node中的一些用到的读取文件方法
  • Dubbo3单端口多协议源码分析
  • 员工拍照泄密?U盘偷拷资料?终端数据安全如何守护?
  • G1垃圾收集器