dotfiles/vim/after/ftplugin/go.vim

75 lines
2.8 KiB
VimL

nmap <silent> <leader>gb :up<bar>:GoBuild<cr>
nmap <silent> <leader>gr :up<bar>:GoRun<cr>
nmap <silent> <leader>gt :up<bar>:GoTest!<cr>
nmap <silent> <leader>gT :up<bar>:GoTest<cr>
nmap <silent> <leader>gf :up<bar>:GoTestFunc!<cr>
nmap <silent> <leader>gF :up<bar>:GoTestFunc<cr>
nmap <silent> <leader>gj :GoDecls<cr>
nmap <silent> <leader>gJ :GoDeclsDir<cr>
nmap <silent> <leader>gk :GoDocBrowser<cr>
nmap <silent> <leader>gv :vsplit<bar>:GoAlternate!<cr>
nmap <silent> <leader>gV <c-w><c-o>:vsplit<bar>:GoAlternate!<cr>
nmap <silent> <leader>gs :split<bar>:GoAlternate!<cr>
nmap <silent> <leader>gS <c-w><c-o>:split<bar>:GoAlternate!<cr>
nmap <silent> <leader>gat <esc>:GoAddTags<cr>
nmap <silent> <leader>grt <esc>:GoRemoveTags<cr>
nmap <silent> <leader>gec <esc>:up<bar>:GoErrCheck<cr>
nnoremap <silent> <leader>_ ciw_<esc>b
nnoremap <silent> dr :GoDebugBreakpoint<cr>
nnoremap <silent> d! :GoDebugStart<cr>
nnoremap <silent> dc :GoDebugContinue<cr>
nnoremap <silent> dq :GoDebugStop<cr>
nnoremap <silent> dn :GoDebugNext<cr>
nnoremap <silent> ds :GoDebugStep<cr>
" Vim-Go configuration
let g:go_gopls_enabled = 0
let g:go_fmt_autosave = 1
let g:go_fmt_command = "goimports"
let g:go_imports_autosave = 0
let g:go_textobj_enabled = 0
let g:go_auto_sameids = 0
let g:go_auto_type_info = 0
let g:go_code_completion_enabled = 0
let g:go_echo_command_info = 0
let g:go_echo_go_info = 0
let g:go_textobj_enabled = 0
let g:go_highlight_diagnostic_errors = 0
let g:go_highlight_diagnostic_warnings = 0
let g:go_highlight_trailing_whitespace_error=0
let g:go_fmt_command = 'goimports'
" g:go_statusline_duration doesn't seem to work accurately, but does help
" reduce the time the build/test success messages are shown in the status
" line.
let g:go_statusline_duration = 1000
autocmd BufNewFile,BufRead *.go nmap <silent> <leader>g6 :GoAlternate!<cr>
iabbrev fmtpl fmt.Println("")<esc>hi
iabbrev fmtpf fmt.Printf("\n")<esc>3hi
iabbrev mk make([]MyType, 0)<esc>9h
iabbrev wr w http.ResponseWriter, r *http.Request
iabbrev ttt t *testing.T
iabbrev errP <esc>ccif err != nil {<cr>panic(err)<cr>}
iabbrev errl <esc>ccif err != nil {<cr>log.Println(err)<cr>}
iabbrev errf <esc>ccif err != nil {<cr>log.Fatal(err)<cr>}
iabbrev errp <esc>ccif err != nil {<cr>fmt.Println(err)<cr>}
iabbrev errr <esc>ccif err != nil {<cr>return err<cr>}
iabbrev defr <esc>ccdefer func() {<cr><cr>}()<esc>ki
iabbrev logd log.Debug().Msg("
iabbrev logi log.Info().Msg("
iabbrev loge log.Error().Msg("
iabbrev logf log.Fatal().Msg("
iabbrev ctxcc ctx context.Context
iabbrev err! err != nil {<cr><cr>}<esc>kcc<c-r>=Eatchar('\s')<cr>
iabbrev ior io.Reader
iabbrev iow io.Writer
iabbrev gof go func() {<cr><cr>}()<esc>kcc<c-r>=Eatchar('\s')<cr>
iabbrev fortc for _, tc := range testCases {<cr>t.Run(tc.name, func(t *testing.T) {<cr><cr>})<cr>}<esc>kkcc<c-r>=Eatchar('\s')<cr>