一、本文提到的vscode用法
- 本机(win)端,安装vscode + 插件
- 服务器(linux)端,配置生产环境,实现远程开发。server可以是:Microsoft Store里面装的wsl、实验室局域网下的linux台式机、买的服务器、VMware里面已启动的虚拟机(通过局域网可以访问)。
二、服务端配置
- 安装ssh,启动ssh服务
- ifconfig查看自己ip(局域网下)
特别提一句 wsl
- wsl是在windows商店里直接下的linux子系统。
- 对于win机器,想要linux环境进行不涉及到linux内核级别的代码开发,也就是写个c/cpp、python之类的,wsl完全可以代替双系统、虚拟机。
三、本机vscode配置
1. vscode下载
- 官网直接下
2. vscode编辑server端的程序代码
- remote-ssh
- 安装完左边会出现这么一个图标,点ssh targets会出现一个加号,点加号会出来一个提示输入ssh 命令的框,输入自己的用户名、ip,再输入密码即可连上。
- 连接后可能会提示再次输入一次密码,之后选择打开文件夹,就会发现可以打开linux端的文件夹了,而且是及时同步的。
- 这样就可以进行代码的编译开发工作。
3. vscode调试server端的可执行程序
- 连接并打开文件夹后,如果想要调试在linux server上运行的程序,修改.vscode/ 底下的launch.json文件即可。
- 对于一般的c/cpp程序,按F5进行调试后,.vscode底下会生成tasks.json和launch.json两个文件,这两个文件挺麻烦的,我也不太会配。
- tasks.json是进行编译的,在这里面配置gcc xx.c 之类的命令,但是对于使用makefile、scons等自己编译的程序,就不需要这个文件编译了,所以这个文件不需要。
- launch.json是加载可执行程序的,在这里面修改要加载的程序为自己想要调试的程序,就可以了。注意的是里面有一个参数"preLaunchTask": “C/C++: gcc-9 build active file”,这个是指定在执行这个配置前要先执行名字为"C/C++: gcc-9 build active file"的一个配置,这个配置也就是说的tasks.json的一个配置的名字,而现在不需要这一行,就把这行删掉就好了。
- 然后launch.json大概长这个样子,这里以运行gem5 的fs模式为例子,具体差不多看着改:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "执行程序的路径/gem5.debug",
"args": [
"参数的路径/configs/example/fs.py",
"-n",
"2",
"省略掉了,不方便透露"
],
"stopAtEntry": false,
"cwd": "",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerArgs": "/usr/bin/gdb"
}
]
}
补充:好用的插件
setting.json(设置在User下,通用)
// 光标行 高亮显示
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#49b2b93d",//修改光标所在行的背景色
"editor.lineHighlightBorder": "#ffffff30" //修改光标所在行的边框色
},
// 自动换行
"editor.wordWrap": "on",
"editor.wordWrapColumn": 80,
vim插件
vscode + vim插件无敌
配置按键:映射
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": false,
// vim插入模式
"vim.insertModeKeyBindings": [
{
"before": [
"j",
"j"
],
"after": [
"<esc>"
]
}
],
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [
"J"
],
"after": [
"j", "j", "j", "j", "j", "j", "j"
]
},
{
"before": [
"K"
],
"after": [
"k", "k", "k", "k", "k", "k", "k"
]
},
{
"before": [
"H"
],
"after": [
"h", "h", "h", "h", "h", "h", "h"
]
},
{
"before": [
"L"
],
"after": [
"l", "l", "l", "l", "l", "l", "l"
]
},
],
powermode打字特效
//是否开启
"powermode.enabled": true,
//效果样式 “水花-particles”, “烟花-fireworks”, “火焰-flames”, “雪花-magic”, “幽灵-clippy”, “激光-simple-rift”, “大激光-exploding-rift”
"powermode.presets": "flames",
//时间间隔
"powermode.comboTimeout": 5,
//是否抖动
"powermode.enableShake": true,
Bracket Pair Colorizer 2
括号匹配
Indent-Rainbow
高亮显示行前的缩进(写python体验极好)
Trailing Spaces
高亮显示行末尾的空格(写markdown体验极好)
附录(配置文件-全部)
{
// 行高亮
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#49b2b93d",//修改光标所在行的背景色
"editor.lineHighlightBorder": "#ffffff30" //修改光标所在行的边框色
},
// vim 配置
"vim.argumentObjectSeparators": [],
"vim.hlsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": false,
// vim插入模式
"vim.insertModeKeyBindings": [
{
"before": [
"j",
"j"
],
"after": [
"<esc>"
]
}
],
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [
"J"
],
"after": [
"j", "j", "j", "j", "j", "j", "j"
]
},
{
"before": [
"K"
],
"after": [
"k", "k", "k", "k", "k", "k", "k"
]
},
{
"before": [
"H"
],
"after": [
"h", "h", "h", "h", "h", "h", "h"
]
},
{
"before": [
"L"
],
"after": [
"l", "l", "l", "l", "l", "l", "l"
]
},
],
"git.autofetch": true,
"git.confirmSync": false,
"editor.tabSize": 2,
"window.zoomLevel": 0.2,
"editor.rulers": [
80
],
"editor.wordWrapColumn": 80,
"debug.onTaskErrors": "debugAnyway",
"editor.fontSize": 14,
"editor.cursorStyle": "line",
"editor.insertSpaces": false,
"editor.lineNumbers": "on",
"editor.wordSeparators": "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-",
// //是否开启
// "powermode.enabled": true,
// //效果样式 “水花-particles”, “烟花-fireworks”, “火焰-flames”, “雪花-magic”, “幽灵-clippy”, “激光-simple-rift”, “大激光-exploding-rift”
// "powermode.presets": "flames",
// //时间间隔
// "powermode.comboTimeout": 5,
// //是否抖动
// "powermode.enableShake": true,
"editor.suggestSelection": "first",
"files.autoSave": "afterDelay",
"remote.SSH.remotePlatform": {
},
"workbench.colorTheme": "One Dark Pro",
"C_Cpp.default.cppStandard": "c++11",
"C_Cpp.default.cStandard": "c11",
"cSpell.userWords": [
"Heapify",
"konghhhhh"
],
"http.proxySupport": "off",
"diffEditor.wordWrap": "off",
"vsicons.dontShowNewVersionMessage": true,
"clang-format.language.javascript.fallbackStyle": "",
"clang-format.language.typescript.fallbackStyle": "",
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"diffEditor.maxComputationTime": 0,
"clang-format.fallbackStyle": "Google",
"workbench.iconTheme": "vscode-icons",
"editor.guides.indentation": false,
"editor.guides.bracketPairs": false,
"editor.inlayHints.enabled": false,
"C_Cpp.clang_format_style": "Google",
"C_Cpp.clang_format_fallbackStyle": "Google",
"files.trimTrailingWhitespace": true,
"terminal.integrated.enableMultiLinePasteWarning": false,
"markdown.extension.list.indentationSize": "inherit",
"[cpp]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"workbench.editorAssociations": {
"*.md": "default"
},
"markdown-preview-enhanced.printBackground": true,
"markdown-preview-enhanced.previewTheme": "vue.css",
"markdown-preview-enhanced.mathInlineDelimiters": [
[
"$",
"$"
],
[
"\\(",
"\\)"
]
],
"workbench.layoutControl.enabled": false,
"diffEditor.ignoreTrimWhitespace": false
}