0%

vscode使用技巧记录

一、前言

  • 据说是宇宙第一IDE,反正vim搞不定的我就用vscode

二、下载加速

  • 将下载链接的地址替换为国内镜像地址vscode.cdn.azure.cn即可

三、好用的插件

1. 跨平台快捷键不一致

  • 在windows上使用习惯的快捷键在linux不适用
  • 安装一个windows default keybinding就好了

2. 16进制查看文件

  • hexdump for vscode

3. cmake

  • CMake: cmake语言支持
  • CMake Tools: vscode界面的cmake工具

踩坑记

(1) tool kits一直没更新

  • 安装了新的gcc,scan之后没有更新
  • 删除/home/sangfor/.local/share/CMakeTools/cmake-tools-kits.json的内容,重新扫描即可

3. remote-ssh

3.1. 服务端组件离线下载地址

  • linux: https://vscode.cdn.azure.cn/stable/(xxx)/vscode-server-linux-x64.tar.gz

4. Draw.io 画图插件

5. vscode-mindmap 思维导图

四、code-server web版vscode

  • 这个东西对付没有界面的服务器又不想在本地安装vscode的很好用

1. 安装

  • 直接下载release包运行即可,地址
  • archlinux可以使用yay进行安装

2. 配置

  • linux配置文件在~/.config/code-server/config.yaml
  • 默认仅提供127.0.0.1的访问,想要外部访问需要配置bind-addr0.0.0.0:8080

3. 使用nginx进行转发,websocket失败导致无法使用

4. arm上安装后无法使用

报错如下

1
Cannot find module '@node-rs/argon2-linux-arm64-gnu'

解决办法

  • 下载https://registry.yarnpkg.com/@node-rs/argon2-linux-arm64-gnu/-/argon2-linux-arm64-gnu-1.1.0.tgz
  • 解压替换到/usr/lib/code-server/node_modules/@node-rs/argon2-linux-arm64-gnu即可

5. 无法选中粘贴

  • web版限制了http访问的部分粘贴功能,需要开启https访问即可

五、调试配置 launch.json

  • json中可用的内置变量

  • ${workspaceFolder} - the path of the folder opened in VS Code

  • ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)

  • ${file} - the current opened file

  • ${fileWorkspaceFolder} - the current opened file’s workspace folder

  • ${relativeFile} - the current opened file relative to workspaceFolder

  • ${relativeFileDirname} - the current opened file’s dirname relative to workspaceFolder

  • ${fileBasename} - the current opened file’s basename

  • ${fileBasenameNoExtension} - the current opened file’s basename with no file extension

  • ${fileDirname} - the current opened file’s dirname

  • ${fileExtname} - the current opened file’s extension

  • ${cwd} - the task runner’s current working directory upon the startup of VS Code

  • ${lineNumber} - the current selected line number in the active file

  • ${selectedText} - the current selected text in the active file

  • ${execPath} - the path to the running VS Code executable

  • ${defaultBuildTask} - the name of the default build task

  • ${pathSeparator} - the character used by the operating system to separate components in file paths

1. gdb

1.1. 配置

1) launch

(1) 本地起程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
// 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": "debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/run",
"args": [], // 参数
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [ // 系统环境变量使用name和value模式指定
{
"name": "LD_LIBRARY_PATH",
"value": "/home/third-party/openssl/"
},
],
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
(2) 连接远程服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/runtime_output_directory/mysqld",
"MIMode": "gdb",
"miDebuggerServerAddress": "127.0.0.1:6666",
"cwd": ".",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}

1.2. 执行gdb命令

  • 启动gdb后,在Debug Console执行-exec xxx即可,-exec后面跟gdb命令

六、配置 settings.json

1. 禁用git

1
2
3
{
"git.enabled": false
}

七、基本使用的一些操作

1. 高级替换

  • 使用()圈起来的正则在替换时按顺序变成$n
  • 需要开启正则匹配

示例

  • 查找abc(.*)=(.*)def
  • 替换abc$2=$1def

效果将abc!@#=*()def替换成abc*()=!@#def

小技巧和踩坑记

1. 在ubuntu上使用管理员打开vscode

1
sudo code --user-data-dir="/path/to/.vscode-root" --no-sandbox --disable-gpu-sandbox