dotfiles/vim/after/ftplugin/go.vim

79 lines
3.1 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 mk make([]MyType, 0)<esc>9h
iabbrev wr w http.ResponseWriter, r *http.Request<c-r>=Eatchar('\s')<cr>
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 fmtpf fmt.Printf("\n")<esc>3hi<c-r>=Eatchar('\s')<cr>
iabbrev fmtpl fmt.Println("")<esc>hi<c-r>=Eatchar('\s')<cr>
iabbrev fmterr fmt.Errorf(": %s", err)<esc>10hi<c-r>=Eatchar('\s')<cr>
iabbrev logpf log.Printf("\n")<esc>3hi<c-r>=Eatchar('\s')<cr>
iabbrev logpl log.Println("")<esc>hi<c-r>=Eatchar('\s')<cr>
iabbrev ctxcc ctx context.Context
iabbrev err! err != nil {<cr><cr>}<esc>kcc<c-r>=Eatchar('\s')<cr>
iabbrev ior io.Reader
iabbrev iorc io.ReadCloser
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>
iabbrev mapss map[string]string
iabbrev mapsi map[string]int
iabbrev mapsa map[string]any
iabbrev mapaa map[any]any