VScode安装和使用(C/C++)

1、简介

VSCode 全称 Visual Studio Code,是微软出的一款轻量级代码编辑器,免费、开源而且功能强大。内置JavaScript、TypeScript和Node.js支持,而且拥有丰富的插件生态系统,可通过安装插件来支持C++、C#、Python、PHP等其他语言。

2、软件下载安装

下载地址:https://vscode.en.softonic.com/download

安装步骤不详细讲解了,无脑下一步即可。

3、扩展插件安装(快捷键 ctrl+shift+x)

3.1、配置中文菜单

Vscode默认为英文菜单,英文用不惯可以在插件商店中搜索chinese,安装中文语言包,重启vscode即可生效。

3.2、配置主题

一个好的主题,能够大大提高我们的编码效率。推荐配置Tiny Light主题,推荐理由:护眼,抗疲劳。

3.3、安装C/C++插件支持

安装C/C++和C++ Intellisense,用于C/C++智能感知功能(跳转、代码补全功能等)。

3.4、安装git插件

虽然vscode内置git版本控制,但是安装插件GitLens后功能会更加强大。

 3.5、安装doxgen插件

doxgen工具能够根据代码注释生成文档,我们只需在写代码时将注释安装doxgen要求的格式写好即可,该插件能够帮助我们更快捷、方便的书写doxgen风格的注释。

4.配置用户代码片段 (自定义代码补全)

快捷键ctrl+shift+P显示所有命令,输入snippets,配置用户代码片段。

比如头文件的自动补全,输入#ifndef,直接补全后面的内容,则需新建全局代码片段json配置文件。

配置文件内容如下所示:

{
	// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	"C header file": {
		"prefix": "#ifndef",
		"body": [
		"#ifndef __$1_H__",
		"#define __$1_H__",
		"",
		"#ifdef __cplusplus",
		"extern \"C\"{",
		"#endif /* __cplusplus */", 
		"",
		"",
		"",
		"",
		"", 
		"#ifdef __cplusplus",
		"}",
		"#endif /* __cplusplus */",
		"#endif /* __$1_H__ */"
		],
		"description": "C header file define"    
	}
}

 配置完成后保存,重启vscode。使用效果如下图所示:

如上所示,大家可以自定义属于自己的代码片段,功能可以说是十分强大。

Vscode的功能远不止于此,还需自己以后慢慢挖掘。

猜你喜欢

转载自blog.csdn.net/fangye945a/article/details/106607539