安装插件
更改插件安装位置
因为默认安装在C:\Users\用户名.vscode\extensions,占c盘目录,所以就找个d盘目录存放插件。
- 先新建一个快捷键
- 打开快捷键的属性
- 在打开时指定插件目录 --extensions-dir 路径
之后下载的插件就在设置的目录下面了
同步配置
安装同步插件Settings Sync
使用GitHub Gist同步多台计算机上的设置,代码段,主题,文件图标,启动,键绑定,工作区和扩展。
-
登陆Github>Your profile> settings>Developer settings>personal access tokens>generate new token,输入名称,勾选Gist,提交 ,保存Github Access Token
-
vscode中Ctrl+Shift+P打开命令框,输入sync,找到update/upload settings,输入Token,上传成功后会返回Gist ID,保存此Gist ID.
-
若需在其他机器上DownLoad插件的话,同样,Ctrl+Shift+P打开命令框,输入sync,找到Download settings,会跳转到Github的Token编辑界面,点Edit,regenerate token,保存新生成的token,在vscode命令框中输入此Token,回车,再输入之前的Gist ID,即可同步插件和设置。
让文件类型一目了然
管理项目
保存项目名字 输入项目名字,按回车
在左边可以看到项目列表
格式化代码
使用命令beautify file来格式化
一键搭建各类语言的学习测试环境
选择语言(以python为例)
运行
网页代码实时预览
使用leetcode插件
使用中国版(不然账号登陆有问题):
登陆即可:
选择题目,点击code now,编写代码,最后提交即可。
编写masm
调试:
主题
使用git
可以看什么时候修改的
远程连接linux
linux上使用gdb
先安装插件
查看一下有没有安装gdb
没有安装就安装一下sudo apt-get install gdb
首先创建一个c++文件
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <semaphore.h>
sem_t sem;
void printer(const char *str)
{
sem_wait(&sem);
while (*str)
{
putchar(*str);
fflush(stdout);
str++;
sleep(1);
}
sem_post(&sem);
}
void *thread_fun1(void *arg)
{
const char *str1 = "hello";
printer(str1);
return NULL;
}
void *thread_fun2(void *arg)
{
const char *str2 = "world";
printer(str2);
return NULL;
}
int main(void)
{
pthread_t tid1, tid2;
sem_init(&sem, 0, 1);
pthread_create(&tid1, NULL, thread_fun1, NULL);
pthread_create(&tid2, NULL, thread_fun2, NULL);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
return 0;
}
不使用make
生成文件命令快捷键
shift+ctrl+p
生成c_cpp_properties.json配置文件(主要是c++的头文件)
默认内容:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
可以修改一下"intelliSenseMode": "clang-x64"
为macos的,改为linux的。
头文件路径也可以添加
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**",
"/usr/lib/x86_64-linux-gnu/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
添加调试的配置launch.json
launch.json默认内容:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "输入程序名称,例如 ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
修改名字为"name": "C++ Debug"
,项目可执行文件路径"program": "${workspaceFolder}/test"
,关键的来了"preLaunchTask": "g++ build"
,这个主要是为了编译可执行文件,没有可执行文件是没法调试的。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "g++ build",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
编译可执行文件
tasks.json默认内容:
{
"tasks": [
{
"type": "shell",
"label": "g++ build",
"command": "/usr/bin/g++",
"args": [
"-g",
"${workspaceFolder}/test.cpp",
"-lpthread",
"-o",
"${workspaceFolder}/test"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
修改版本"version": "2.0.0"
,可以
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build",
"command": "/usr/bin/g++",
"args": [
"-g",
"${workspaceFolder}/test.cpp",
"-lpthread",
"-o",
"${workspaceFolder}/test"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
下断点调试就好了
最后文件夹长这样
使用make
我们文件多了一般都使用make的
#编译器
CC=g++
#目标名
obj=test
#使用c++11语法
CPPFLAGS=-Wall -g -std=c++11 -lpthread
#使用$(wildcard *.cpp)来获取工作目录下的所有.cpp文件的列表
sources:=$(wildcard *.cpp)
objects:=$(sources:.cpp=.o)
#这里,dependence是所有.d文件的列表.即把串sources串里的.cpp换成.d
dependence:=$(sources:.cpp=.d)
$(obj):$(objects)
$(CC) $(CPPFLAGS) $^ -o $@
%.d: %.cpp
@set -e; rm -f $@; \
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
#注意该句要放在终极目标规则之后,否则.d文件里的规则会被误当作终极规则了
-include $(dependence)
#运行
run:
./$(obj)
#清理
clean:
rm -rf *.o *.d $(obj) a.out
修改我们的task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build",
"command": "make",
"args": [
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
下断点调试就好了(可以看到这边执行的是我们的make命令)
最后文件夹长这样