kubernetes集群三步安装 探讨可加QQ群:98488045

使用vim作golang开发

分享一些我使用的vim插件,以及制作过程,最终的功能有:

  • golang开发,补全,跳转,文件列表,函数列表等
  • kubernetes插件,方便写yaml文件
  • 好看的颜色主题

先睹为快:

安装macvim

主要是YouCompleteMe mac系统上需要依赖这个地址

非mac环境我会提供一个docker镜像

安装插件管理器vundle

1
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

我的~/.vimrc

  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
105
106
set nocompatible              " be iMproved, required
" 🔑  (key)
let mapleader=","
filetype off "required

set foldmethod=indent

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
" Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
Plugin 'L9'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Plugin 'nsf/gocode',{'rtp':'vim/'}
Plugin 'fatih/vim-go'
Bundle 'scrooloose/nerdtree'
"Bundle 'cespare/vim-golang'
" Bundle 'dgryski/vim-godef'
Plugin 'Valloric/YouCompleteMe'
" Plugin 'SirVer/ultisnips'
" Plugin 'majutsushi/tagbar'
Plugin 'vim-scripts/taglist.vim'
" Plugin 'junegunn/vim-emoji'
" Plugin 'rjohnsondev/vim-compiler-go'
" Plugin 'dgryski/vim-godef'
" Plugin 'davidhalter/jedi-vim'
" Plugin 'scrooloose/syntastic'

call vundle#end()            " required
filetype plugin indent on    " required

nmap <C-h> <C-w>h
nmap <C-l> <C-w>l
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k

map <C-n> :NERDTreeToggle<CR>
map <C-t> :b 1 <CR>


Bundle 'majutsushi/tagbar'
nmap <Leader>t :TagbarToggle<CR>
let g:tagbar_width = 25
autocmd VimEnter * nested :call tagbar#autoopen(1)
autocmd BufWritePre *.go:Fmt
let g:tagbar_right = 1
let g:Tlist_Ctags_Cmd='/usr/local/Cellar/ctags/5.8_1/bin/ctags'

let g:molokai_original = 1
let g:rehash256 = 1
set sw=4

colorscheme molokai

set nu
set ts=4
set expandtab
syntax on

let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_fmt_command = "goimports"
let g:go_fmt_fail_silently = 1
let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }

let g:UltiSnipsExpandTrigger="<C-g>"

let g:godef_split=2
let g:godef_same_file_in_same_window=1

au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>T <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)

au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dt <Plug>(go-def-tab)

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
set completefunc=emoji#complete
map <C-e> :%s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g <CR>

set lines=120 columns=150

启动vim 执行 :PluginInstall

安装YouCompleteMe

安装brew ctags cmake:

1
2
3
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install cmake
brew install ctags-exuberant

必须要安装好golang再进行以下步骤

1
2
cd ~/.vim/bundle/YouCompleteMe
./install.py --clangd-completer --go-completer

初始化vim-go

启动vim执行 :GoInstallBinaries (要访问golang官网,所以你懂的)

安装颜色主题

1
2
git clone https://github.com/tomasr/molokai ~/.vim
mv ~/.vim/molokai/colors ~/.vim

常用快捷键

Ctrl n 文件目录 , t 函数列表 ,dt 跳转到函数定义

更多内容

为什么写这篇文章,因为fist 的webterminal里会集成这样一个vim,webterminal就具备非常强大的k8s管理能力,特别是编写yaml配置文件,就可以做到比如你输入一个dep补全后就直接生成一个Deployment配置,非常高效,还语法高亮,yaml语法检测等,是不是很期待~

公众号:

sealyun

微信群: