软件下载
vscode软件下载:https://code.visualstudio.com/
安装vs_code
参考文件文档:
https://www.liwenzhou.com/posts/Go/00_go_in_vscode/
安装Go插件Update Tools
方法一:
我们可以手动从github上下载工具,(执行此步骤前提需要你的电脑上已经安装了git)
第一步:现在自己的GOPATH的src目录下创建golang.org/x目录
第二步:在终端/cmd中cd到GOPATH/src/golang.org/x目录下
第三步:执行git clone https://github.com/golang/tools.git tools命令
第四步:执行git clone https://github.com/golang/lint.git命令
第五步:按下Ctrl/Command+Shift+P再次执行Go:Install/Update Tools命令,在弹出的窗口全选并点击确定,这一次的安装都会SUCCESSED了。
经过上面的步骤就可以安装成功了。 这个时候创建一个Go文件,就能正常使用代码提示、代码格式化等工具了。
linux环境下安装Go语言开发工具包的坑:
安装时可能会报失败:
解决方法
- 配置好Go环境变量:
配置跳过
sudo vim /etc/profile
export GOROOT="/usr/local/go"
export GOPATH=$HOME/go export
GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
按esc -> shift+; -> wq 回车保存并退出
source profile
go version
2.配置vscode的go环境变量
文件->首选项->设置:
搜索:Associations 打开settings.json
{
"workbench.colorTheme": "Monokai",
"editor.mouseWheelZoom": true,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 3000,
"go.goroot":"/usr/local/go",
"go.gopath":"/home/haima/go",
"go.gobin":"/home/haima/go/bin",
"go.toolsGopath":"/home/haima/go",
"go.gocodeAutoBuild":false
}
再执行上面的第五步
方法二:下载已经编译好的可执行文件
如果上面的步骤执行失败了或者懒得一步一步执行,可以直接下载我已经编译好的可执行文件,拷贝到自己电脑上的 GOROOT/bin 目录下。
这里我放在GOPATH/bin目录里
我的GOPATH是GOPATH=”/home/haima/go”
go-tools百度云下载链接,
链接: https://pan.baidu.com/s/1yWjh556iyye1AAmG6o57Dw 提取码: mk3n
下载自己对应环境的编译文件:
注意:特别是Mac下需要给拷贝的这些文件赋予可执行的权限。
安装插件
Go #go语言支持包
code runner插件 #运行go程序
GitLens — Git supercharged #git历史版本管理
vscode-proto3 # proto3 support
live preview # 前端html预揽插件
vue2用这个
- Vetur
vue3用这个
- Vue 3 Support - All In One
- TypeScript Vue Plugin (Volar) (弃用) –> Vue - Official
修改快捷键
打开快捷键 File->Preferences->Keyboard Shortcuts
双击要修改的快捷键
键盘输入想要使用的快捷键
快速生成代码片段
alt + 上下键 上下移动整行
pkgm main包+main主函数
ff fmt.Printf("", var)
for for i := 0; i < count; i++ {}
forr for _, v := range v {}
fmain func main() {}
a.print! fmt.Printf("a: %v\n", a)
curl+单击函数名 函数追踪
推荐几款好用的VsCode色彩主题
https://blog.csdn.net/lwx931449660/article/details/108522666
【VSCode】vscode中配置默认终端为git-bash
第一步,找到你安装Git的目录,在bin目录下有个bash.exe,复制bash的地址,比如:D:\Program Files\Git\bin\bash.exe
第二步,打开Vscode, 点击左下角【设置】
加入下面的设置
点右上角转为json设置
写入下面的设置代码
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Bash": {
"path": "D:\\Program Files\\Git\\bin\\bash.exe",
"args": []
}
},
"terminal.integrated.defaultProfile.windows": "Bash",
第二步 重启Vscode ,打开控制台终端,此时终端变成了我们喜欢的 bash 窗口了:
vscode debug代码
最后编辑:海马 更新时间:2025-01-27 10:57