1 vscode 快捷键 🔗
1.1 工作区快捷键 🔗
Cmd + Shift + P -》显示命令面板
Cmd+P -》 在当前的项目工程里,全局搜索文件名
Cmd + B -》 显示/隐藏侧边栏
Cmd + J -》 显示/隐藏控制台
预览 md 格式(⇧⌘V)
1.2 跳转操作 🔗
ctrl + G -》 跳转到指定行
在代码里穿梭。
阅读代码时最重要的 2 个功能。从 caller 跳转到定义, command + 鼠标单击。 从定义原路返回到 caller。
跳转到类型的定义 -》 cmd + 鼠标左键 or option + = (自改键)
Cmd+Alt+Click. -》open the definition to the side bar
跳转后的原路返回 -》 option + - (自改键)
1.3 移动光标 🔗
option + 左右方向键 -》 在单词之间移动光标
cmd + 左右方向键 -》在整行之间移动光标
1.4 搜索 🔗
Cmd + Shift + F -》 全局搜索代码
Cmd + P -》 全局搜索文件名 例如 main.rs:18
1.5 自定义快捷键 🔗
- 快捷键内置查询表 菜单栏-》帮助-》快捷键参考-》very good
- 自定义快捷键: 文件—》首选项-》键盘快捷方式
2 vscode 配置文件 🔗
User Settings - Settings that apply globally to any instance.
Workspace Settings - Settings stored inside your workspace
and only apply when the workspace is opened.
2.1 全局配置 user Settings 🔗
界面上 User Settings editor 只是为了方便界面修改,修改后的配置保存在 settings.json 全局文件中。
全局配置文件 settings.json:Mac 下 vs code 设置文件:$HOME/Library/Application Support/Code/User/settings.json。
2.2 每个项目的配置 workspace settings 🔗
workspace settings override user settings.
每个项目的配置在项目根目录的.vscode 文件夹中。
- 局部配置(项目自身的配置)settings.json
- debugging configuration settings
- task Configuration settings tasks.json
3 vs code 的编程语言插件 🔗
3.1 golang 环境配置 🔗
插件 extensions: go
其他命令工具 cmd+shit+p 输入 goinstall
3.1.1 遇到的问题 🔗
最开始使用run test时无输出, 在settings.json里添加"go.testFlags":["-V"],
golang 源码的提示问题。
3.2 rust 环境配置 🔗
插件:the rust-analyzer extension
编译器:installed via the rustup installer
验证一下编译器是否安装:rustc --version
3.3 c/c++ 环境配置 🔗
官方文档:https://code.visualstudio.com/docs/cpp/introvideos-cpp 介绍了如何配置智能提示(c_cpp_properties.json),如何配置编译项目(tasks.json),如何调试项目(launch.json)
特别在 macos 上使Using Clang in Visual Studio Code
插件: Microsoft C/C++ extension 。
编译器:Linux 的 GNU Compiler Collection (GCC) 和 macOS 的 Clang tools with Xcode 已经安装了。
验证一下编译器是否安装 g++ --version, clang --version
- .vscode 文件夹
- tasks.json (compiler build settings),告诉 VS Code 如何编译程序
- launch.json (debugger settings),执行调试程序的入口文件。
- c_cpp_properties.json (compiler path and IntelliSense settings) ,编译器路径和 IntelliSense 设置
遇到的问题 🔗
Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.
gcc -g x.c or clang -g x.c带上-g编译产生可执行文件。
--verbose 操作的详细过程。
glibc/csu/libc-start.c#LIBC_START_MAIN()
在_start处设置断点, libc-start.c”: 'SourceRequest' not supported。
下载glibc源码,放到/usr/src/glibc/glibc-2.35。 配置launch.json中的sourceFileMap。
Entry point: 0x600
错误:cannot insert breakpoint 2. cannot access memory at address
(gdb) set stop-on-solib-events 1
ubuntu@primary:~/NJU_OS$ gcc -fno-pie -no-pie -g -o hello.out hello.c -march=i386
cc1: error: unknown value ‘i386’ for ‘-march’
cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8-r native
neovim 🔗
可自己定制化的增加和删除功能的编辑器。
nerdfonts, nvim-tree, dap, dap-ui, treesitter, nvim-telescope
安装 neovim 和 packer 插件管理器。
安装 neovim 🔗
- 插件管理器 Packer,
- 安装 mason(帮助安装代码相关的插件,lsp, dap-server, linter, formatter),mason-lspconfig
- 安装 nvim-lspconfig ()
- mason 下载 gopls,
LspInfo看 lsp 的日志,排查 lsp 没生效的情况 - 增加
code completion和suggestions的插件,hrsh7th/nvim-cmp- 改键
- nvim-tree,
- mason 下载 DAP 支持 debug 和 UI
- Dracula 主题
- treesitter 更好的代码高亮
- linters, formatters
- telescope 搜索
- lualine 状态栏
- 其他推荐的插件
- autopair (done)
- bufferline (done)
- IndentBlankline, Guide for indention (done)
- comment ( 增加注释 done)
- lspSaga, Code Actions, Floating Hover docs, etc. (不稳定的插件)
- FloatTerm , Open floating terminals, good for such as opening LazyGit.
- done
- Nvim-Lint, Linter! Much needed.
- trouble, Think VS Code Buttom Error tab (done)
- TodoComments (done)
- Tagbar, an overview of the structure, functions [https://github.com/preservim/tagbar]
- 依赖 ctags 的安装。 done
通过 brew 源 🔗
macos 可以这样安装brew install neovim,之后就可以nvim
:checkhealth
更新 neovimbrew upgrade neovim
通过 github 的 release 🔗
从 github 下载压缩包: curl https://github.com/neovim/neovim/releases/download/stable/nvim-xxx.tar.gz
解压缩:tar -xvf nvim-xxx.tar.gz ,将解压后的软件包中./nvim-xxx/bin/nvim的路径添加到$PATH中,就可以nvim了。
插件管理器 packer 🔗
在 nvim 中输入:echo stdpath('data')可以找到用来安装插件系统的文件夹。
在 nvim 中输入 :echo stdpath('config') 可以找到存放配置文件的文件夹。
在 neovim 中 pressing SHIFT + : 切换为命令模式, SHIFT + %创建新文件。
packer.nvim
git clone --depth 1 https://github.com/wbthomason/packer.nvim\ ~/.local/share/nvim/site/pack/packer/start/packer.nvim。
插件的安装地址:~/.local/share/nvim/site/pack/packer/start。
所有插件的 config 地址在~/.config/nvim/lua中的 lua 文件中, mkdir -p ~/.config/nvim/lua && nvim ~/.config/nvim/lua/plugins.lua。
:Explore 导航
:PackerStatus 列出所有的插件。
~/.config/nvim/init.lua neovim 启动时加载插件 , ~/.config/nvim/lua/plugins.lua利用 packer 导入插件
language server 🔗
想要成为 IDE,需要使用 language server 去明白代码。Mason
:luafile % reload lua 文件。
:PackerInstall
:Mason 列出可用的 LSPs。 安装一个 lsp MasonInstall gopls
code completion & suggestions 现在还没有。hrsh7th
:PackerSync 删除无用的插件,下载新插件。
出现使用上的问题 🔗
执行:w时, "readme.md" 27L, 511B 已写入
处理 BufWritePost 自动命令 "*" 时发生错误:
Error running vale: ENOENT: no such file or directory。
遇到的问题。 🔗
:lua require("neotest").log.open()遇到如下:
E5108: Error executing lua [string ":lua"]:1: attempt to index field 'log' (a nil value) stack traceback: [string ":lua"]:1: in main chunk
使用 🔗
:help nvim-features
在.config文件夹下,创建文件夹~/.config/nvim, 创建init.lua, 创建lua文件夹。
~/.config/nvim/ --nvim的管理目录·
init.lua
lua/
core/ --nvim核心脚本存放目录
options.lua
keymaps.lua
plugins/ --nvim插件脚本存放目录
plugins-setup.lua
Mason lsp 的插件管理。
https://rsdlt.github.io/posts/rust-nvim-ide-guide-walkthrough-development-debug/
按a创建 file,按d删除文件。
lazyvim 🔗
其他 neovim 的快速方案,LunarVim Neovim from scratch
lsp 🔗
python 需要安装pyright
markdown preview 出现的问题 🔗
问题:MarkdownPreview没有渲染的反应, :messages查看到错误信息如下:
node:internal/modules/cjs/loader:1078
throw err;
^
Error: Cannot find module 'tslib'
可以看issue的解决方案比较靠谱。
解决方式: sudo npm install --global yarn, cd markdown-preview插件的安装地址 && yarn install && upgrade
命令 🔗
shift + :Explore, 之后shift + %创建文件。
:checkhealth
go development plugin,gopls, treesitter AST, Dap, others 🔗
golang debug with delve 🔗
检查安装好后,dlv version
开始使用说明dlv help, debug debug main.go, 入口为测试文件时debug test a_test.go
list main.main, list ./main.go:14, break ./main.go:10, continue
next,step 跳进函数内, stepout跳出函数
print x , locals
4 其他编辑器 🔗
- nano
- vim/tmux
- vim 中执行命令
- :!rm compile_commands.json 删除 vim .中的一个文件。
- ctags -R
- ctrl + ](), ctrl + t()
- ctrl + g 显示当前文件的路径位置。
- 遇到宏或者函数指针可能无法使用,暴力搜索。
- /some_string, n 是往下找, N 是往上找。vim 统计查找匹配个数。:%s/pattern//gn
- vim, :ta start_kernel 找到起始函数的代码。:ts 查找函数出现的位置。
- linux 从 kernel 转移到 user space:start_kernel -> rest_init -> kernel_init -> init_post -> init
- cscope -Rq
- vim 中执行命令
- emacs
reference 🔗
[1] Getting Started
[2] golang in vs code
[3] c/c++ in vs code
[4] C++ IntelliSense
[5] rust in vs code
[6] PC搜索插件的地址
[7] learn how to use neovim as an ide
[8] 从零开始配置Neovim
[9] go neovim config
[10] golang debugging with delve