https://github.com/fatih/vim-go-tutorial#quick-setup
,r 运行
,b 构建
,t 测试
,c 查看哪些方法没写测试
vif vaf dif daf yif yaf 选中,删除,复制方法快捷键
gS gJ 把一行长的代码,打成多行短代码,或者反向合并
snippets 快捷生成代码模板,比如输入ff 然后 tab, 会自动生成 fmt.Printf(" = %+v\n")
https://github.com/fatih/vim-go/blob/master/gosnippets/UltiSnips/go.snippets
常用的如:fn, ff, ln, lf, errp
gd/ctrl + ] 定位定义的地方,ctrl t, 回来
:A, :AV, :AS and :AT. 主文件和test文件之间切换,V 竖向分屏,S横向分屏,T新建TAB
:GoRename bar 把当前光标的变量重命名为bar
:GoImpl 生成当前光标所在struct,要继承哪。:GoImpl b *B fmt.Stringer, 生成B的Stringer接口的方法,变量名为b
:GoPlay
let mapleader = ","
set autowrite
set nocompatible " Disable compatibility to old-time vi
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set mouse=v " middle-click paste with mouse
set hlsearch " highlight search results
set tabstop=4 " number of columns occupied by a tab character
set softtabstop=4 " see multiple spaces as tabstops so <BS> does the right thing
set expandtab " converts tabs to white space
set shiftwidth=4 " width for autoindents
set autoindent " indent a new line the same amount as the line just typed
set number " add line numbers
set wildmode=longest,list " get bash-like tab completions
set cc=80 " set an 80 column border for good coding style
" set tab, default 4 space
" set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
" Spaces & Tabs {{{
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " number of spaces to use for autoindent
set expandtab " tabs are space
set autoindent
set copyindent " copy indent from the previous line
" }}} Spaces & Tabs
autocmd BufNewFile,BufRead,BufWrite *.go setlocal tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
" html/js/coffe/jade, use 2 space
autocmd Filetype html setlocal ts=2 sw=2 expandtab
autocmd Filetype javascript setlocal ts=2 sw=2 expandtab
autocmd Filetype coffeescript setlocal ts=2 sw=2 expandtab
autocmd Filetype jade setlocal ts=2 sw=2 expandtab
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
call plug#begin()
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
Plug 'AndrewRadev/splitjoin.vim'
Plug 'SirVer/ultisnips'
Plug 'fatih/molokai'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tpope/vim-fugitive'
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
call plug#end()
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
let g:go_fmt_command = "goimports"
let g:go_fmt_fail_silently = 1
let g:go_addtags_transform = "camelcase"
let g:go_list_type = "quickfix"
let g:go_test_timeout = '10s'
let g:go_highlight_types = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:go_metalinter_autosave = 1
let g:go_metalinter_deadline = "5s"
let g:go_auto_sameids = 1
let g:rehash256 = 1
let g:molokai_original = 1
colorscheme molokai
autocmd FileType go nmap <Leader>i <Plug>(go-info)
let g:go_auto_type_info = 1
" nerdtree
map <F2> :NERDTreeToggle<CR>
let NERDTreeQuitOnOpen=1
" auto locate to last edit positon
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
set updatetime=100