当前位置:网站首页>Vim配置Golang开发环境
Vim配置Golang开发环境
2022-07-25 05:38:00 【m0_52339560】
Vim配置Golang开发环境
准备:
Download Ubuntu Desktop | Download | UbuntuUbuntu 22.04 LTS
安装好Vim
下载好GoLang工具包,这会在后面介绍。
有一定的vim使用经验
开始:
下载Go package。Downloads - The Go Programming Language (google.cn)
解压下载的包。
$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.4.linux-amd64.tar.gz命令要以root身份执行。同时,不要解压到已存在的/usr/local/go目录中,否则会破坏golang的安装,所以需要先删除/usr/local/go目录。添加
/usr/local/go/bin到环境变量中:
可以将下面这一行添加到
$HOME/.profile或者/etc/profile中:
export PATH=$PATH:/usr/local/go/bin然后使用
source /etc/profile,或者source /$HOME/.profile来更新配置。这取决与你修改的那一个文件。
验证是否安装并配置成功:
$ go version,如果配置成功,会打印安装go的版本信息。设置代理:
这一步非常重要。这里设置的是七牛云的代理。
假定你在第3步,修改了
/etc/profile文件,那么就继续向该文件写入配置。这里设置代理的方法有很多种,可以参看笔者文末的参考资料。export GO111MODULE=on export GOPROXY=https://goproxy.cn写入完成后,保存退出,并输入终端命令:
source /etc/profile,更新配置。
取消代理:如果某一天要取消代理,那么可是输入终端命令:
go env -u GOPROXY。查看Go的配置:
go env或者go env -json。后者表示以json格式输出go的配置。
到这里,go的一些工具包基本安装完成。下面开始配置vim。
这里主要使用的是vim-plug插件管理器,以及vim-go插件。vim-plug的安装,参看笔者过去写的一篇文章。这里不再赘述。CentOS 8 下配置Vim及其插件_m0_52339560的博客-CSDN博客_centos vim 插件
" 插件列表
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'
"对代码段进行展开
Plug 'honza/vim-snippets'
" 解决snipet和YCM冲突的插件
Plug 'ervandew/supertab'
“vim-go插件
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
"安装的主题插件
Plug 'flazz/vim-colorschemes'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'SirVer/ultisnips'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-commentary'
" 加载自定义插件
if filereadable(expand($HOME . '/.vimrc.custom.plugins'))
source $HOME/.vimrc.custom.plugins
endif
call plug#end()
添加了部分插件后,输入:PlugInstall并按下回车。等待插件自动安装。可能会出现插件安装失败的情况,可以多试着安装几次,实在不行可以去百度,google。关于其他插件的使用方法可以自行去github上搜索,一般都有对应的使用手册。
待vim-go插件安装好后,还需要安装一些依赖。这里使用vim打开一个文件,然后输入:GoInstallBinaries。这里如果没有设置国内代理,就会下载失败。
let mapleader = " " "设置leader键位空格
"vim-go的配置
autocmd FileType go nmap <leader>b <Plug>(go-build)
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
set autowrite "自动写入
let g:go_list_type = "quickfix" "在退出文件时,自动进行错误检查,并将错误展示在一个新窗口
let g:go_fmt_command = "goimports" "在保存文件时,自动格式化go代码,并且自动更新依赖库。在大型项目中会很慢。
"let g:go_fmt_fail_sliently = 1 "关闭保存文件时的格式化检查
let g:go_addtags_transform = "camelcase" "驼峰命名法
ctrl+]转到定义处,ctrl+o回到上一个跳转处。:GoRun运行go代码,这里配置成了空格+r.关于vim-go的使用技巧有很多。
这里主要的插件就是vim-go,可以去github上搜索这个插件,里面也有详细的使用手册可以参考。这里不做过多介绍。并且网上关于vim 下golang环境配置的文章很多。
参考资料
边栏推荐
- AirServer 7.3.0中文版手机设备无线传送电脑屏幕工具
- Base64 (conversion between string and Base64 string)
- Sword finger offer 05. replace spaces
- Differences and application directions of GPS, base station and IP positioning
- Zhanrui's first 5g baseband chip was officially released and successfully ranked among the first tier of 5g!
- Leetcode 237. 删除链表中的节点
- Array programming problem of CSDN programming challenge
- 批量下载视频小技巧
- sqlilabs less-28~less-8a
- Leetcode 204. count prime numbers (wonderful)
猜你喜欢

Win11 how to view the file explorer tab

JWT(json web token)

C100: smallest hevc visual IOT MCU

Necessary skills for mobile terminal test: ADB command and packet capturing

微服务 - 配置中心 - Nacos

VIM search and replacement and the use of regular expressions

编程大杂烩(二)

Array programming problem of CSDN programming challenge

传输线理论之相速、相位等的概念

Unity accesses chartandgraph chart plug-in
随机推荐
School day (summer vacation daily question 2)
JWT(json web token)
LCP插件创建对等802.1ad接口
G1 garbage collector
Introduction summary of using unirx in unity
Airserver 7.3.0 Chinese version mobile device wireless transmission computer screen tool
Array programming problem of CSDN programming challenge
LCP插件创建对等物理接口
2021 ICPC Shaanxi warm up match b.code (bit operation)
Leetcode 202. happy number (not happy at all)
Obj file format and.Mtl file format
微服务 - Hystrix 熔断器
单点登录(一处登录,处处可用)
聊聊 Redis 是如何进行请求处理
Introduction to interface in SystemVerilog
Adaptation dynamics | in June, sequoiadb completed mutual certification with five products
An SQL execution process
sqlilabs less-29
06. Libavdevice Library of ffmpeg
HTB-Beep