" Copyright 2013 The Go Authors. All rights reserved. " Use of this source code is governed by a BSD-style " license that can be found in the LICENSE file. " " go.vim: Vim filetype plugin for Go. if exists("b:did_ftplugin") finish endif let b:did_ftplugin = 1 " don't spam the user when Vim is started in Vi compatibility mode let s:cpo_save = &cpo set cpo&vim let b:undo_ftplugin = "setl fo< com< cms< \ | exe 'au! vim-go-buffer * '" setlocal formatoptions-=t setlocal comments=s1:/*,mb:*,ex:*/,:// setlocal commentstring=//\ %s setlocal noexpandtab compiler go " Set autocompletion setlocal omnifunc=go#complete#Complete if !go#util#has_job() setlocal omnifunc=go#complete#GocodeComplete endif if get(g:, "go_doc_keywordprg_enabled", 1) " keywordprg doesn't allow to use vim commands, override it nnoremap K :GoDoc endif if get(g:, "go_def_mapping_enabled", 1) " these are default Vim mappings, we're overriding them to make them " useful again for Go source code nnoremap gd :GoDef nnoremap :GoDef nnoremap :GoDef nnoremap g :GoDef nnoremap :call go#def#Jump("split", 0) nnoremap ] :call go#def#Jump("split", 0) nnoremap :call go#def#StackPop(v:count1) endif if get(g:, "go_textobj_enabled", 1) onoremap af :call go#textobj#Function('a') xnoremap af :call go#textobj#Function('a') onoremap if :call go#textobj#Function('i') xnoremap if :call go#textobj#Function('i') onoremap ac :call go#textobj#Comment('a') xnoremap ac :call go#textobj#Comment('a') onoremap ic :call go#textobj#Comment('i') xnoremap ic :call go#textobj#Comment('i') " Remap ]] and [[ to jump betweeen functions as they are useless in Go nnoremap ]] :call go#textobj#FunctionJump('n', 'next') nnoremap [[ :call go#textobj#FunctionJump('n', 'prev') onoremap ]] :call go#textobj#FunctionJump('o', 'next') onoremap [[ :call go#textobj#FunctionJump('o', 'prev') xnoremap ]] :call go#textobj#FunctionJump('v', 'next') xnoremap [[ :call go#textobj#FunctionJump('v', 'prev') endif if go#config#AutoTypeInfo() || go#config#AutoSameids() let &l:updatetime= get(g:, "go_updatetime", 800) endif " Autocommands " ============================================================================ " augroup vim-go-buffer autocmd! * " The file is registered (textDocument/DidOpen) with gopls in in " plugin/go.vim on the FileType event. " TODO(bc): handle all the other events that may be of interest to gopls, " too (e.g. BufFilePost , CursorHold , CursorHoldI, FileReadPost, " StdinReadPre, BufWritePost, TextChange, TextChangedI) if go#util#has_job() autocmd BufWritePost call go#lsp#DidChange(expand(':p')) autocmd FileChangedShell call go#lsp#DidChange(expand(':p')) autocmd BufDelete call go#lsp#DidClose(expand(':p')) endif autocmd CursorHold call go#auto#auto_type_info() autocmd CursorHold call go#auto#auto_sameids() " Echo the identifier information when completion is done. Useful to see " the signature of a function, etc... if exists('##CompleteDone') autocmd CompleteDone call go#auto#echo_go_info() endif autocmd BufWritePre call go#auto#fmt_autosave() autocmd BufWritePost call go#auto#metalinter_autosave() " clear SameIds when the buffer is unloaded so that loading another buffer " in the same window doesn't highlight the most recently matched " identifier's positions. autocmd BufWinEnter call go#guru#ClearSameIds() autocmd BufEnter \ if go#config#AutodetectGopath() && !exists('b:old_gopath') \| let b:old_gopath = exists('$GOPATH') ? $GOPATH : -1 \| let $GOPATH = go#path#Detect() \| endif autocmd BufLeave \ if exists('b:old_gopath') \| if b:old_gopath isnot -1 \| let $GOPATH = b:old_gopath \| endif \| unlet b:old_gopath \| endif augroup end " restore Vi compatibility settings let &cpo = s:cpo_save unlet s:cpo_save " vim: sw=2 ts=2 et