vim打造自己的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. 修改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

使用

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

自动补全

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

预览
1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值