当前位置:   article > 正文

vim打造自己的go IDE_nvim搭建go ide

nvim搭建go ide

打造适合自己的go IDE

前几天mac出了点问题,公司给换了一台,唯一不爽的就是原有的环境要重建,记录下

  1. 依赖 安装
# brew 安装
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# iterm2 安装
brew cask install iterm2
# vim 安装
brew install vim
# Vundle (插件管理器) 安装
mkdir -p ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# npm 安装
brew install npm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  1. 修改vim配置~/.vimrc
"==============================================================================
" vim 内置配置
"==============================================================================

" 设置 vimrc 修改保存后立刻生效,不用在重新打开
" 建议配置完成后将这个关闭
autocmd BufWritePost $MYVIMRC source $MYVIMRC

set nocompatible " 关闭兼容模式
set nu " 设置行号
set cursorline "突出显示当前行
set cursorcolumn " 突出显示当前列
set showmatch " 显示括号匹配
set mouse=v " 允许鼠标点击定位
set paste " 粘贴时保持格式
set ruler " 显示当前光标所在的行列号
set scrolloff=3 " 标移动到buffer的顶部和底部时保持3行距离
set nowrap " 取消换行

" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936

" 允许使用退格键
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

" tab 缩进
set tabstop=4 " 设置Tab长度为4空格
set shiftwidth=4 " 设置自动缩进长度为4空格
set autoindent " 继承前一行的缩进方式,适用于多行注释

" 定义快捷键的前缀,即<Leader>
let mapleader=";"

"vundle 配置
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'fatih/vim-go'
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plugin 'junegunn/fzf.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'Valloric/YouCompleteMe'
Plugin 'dgryski/vim-godef'
call vundle#end()

" vim-go
au FileType go nmap C :GoCoverage<CR>
au FileType go nmap gl :GoDeclsDir<CR>
au FileType go nmap c :GoDoc<CR>
au FileType go nmap gs :GoImports<CR>
au FileType go nmap gi :GoInfo<CR>
au FileType go nmap e  :GoRename<CR>
au FileType go nmap gr :GoRun<CR>
au FileType go nmap gc :GoCallers<CR>
au FileType go nmap gb :GoBuild<CR>
au FileType go nmap D :GoDef<CR>
au FileType go nmap gt :GoDefType<CR>
autocmd BufWritePost *.go :GoVet!
let g:go_asmfmt_autosave = 1
let g:go_auto_sameids = 1
let g:go_auto_type_info = 1
let g:go_def_mode = 'gopls'
let g:go_doc_keywordprg_enabled = 1
let g:go_doc_max_height = 25
let g:go_echo_command_info = 1
let g:go_echo_go_info = 1
let g:go_fmt_autosave = 1
let g:go_fmt_command = "goimports"
let g:go_imports_command = "gopls"
let g:go_implements_mode = "gopls"
let g:go_imports_autoremove = 1
let g:go_referrers_mode = "gopls"
let g:go_doc_popup_window=1
let g:go_gopls_complete_unimported = 1
let g:go_gopls_enabled = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_function_parameters = 1
let g:go_highlight_functions = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_interfaces = 0
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
let g:go_info_mode = 'gopls'
let g:go_mod_fmt_autosave = 1
let g:go_template_autocreate = 0
let g:go_textobj_include_function_doc = 1
let g:go_autodetect_gopath = 1
let g:go_metalinter_autosave = 0

" 开启实时搜索
set incsearch
" 搜索时大小写不敏感
set ignorecase
syntax enable
syntax on                    " 开启文件类型侦测
filetype plugin indent on    " 启用自动补全

" 退出插入模式指定类型的文件自动保存
au InsertLeave *.go,*.sh,*.php write
  • 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
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104

使用

  • 打开vim输入:PluginInstall会安装.vimrc文件列出来的所有插件
  • 仅安装指定插件:PluginInstall plugin-name
  • 命令行安装vim +PluginInstall +qall

自动补全

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all
  • 1
  • 2

预览
1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/340620
推荐阅读
相关标签
  

闽ICP备14008679号