1
0
Fork 0
mirror of synced 2024-12-27 00:53:20 -05:00
ultimate-vim/sources_non_forked/vim-go/ftplugin/go.vim

125 lines
4.2 KiB
VimL
Raw Normal View History

2014-10-31 17:30:24 -04:00
" 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")
2016-06-26 07:12:36 -04:00
finish
2014-10-31 17:30:24 -04:00
endif
let b:did_ftplugin = 1
2018-12-17 06:28:27 -05:00
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
2019-03-08 06:04:56 -05:00
let b:undo_ftplugin = "setl fo< com< cms<
\ | exe 'au! vim-go-buffer * <buffer>'"
2014-10-31 17:30:24 -04:00
setlocal formatoptions-=t
setlocal comments=s1:/*,mb:*,ex:*/,://
setlocal commentstring=//\ %s
setlocal noexpandtab
compiler go
2019-03-27 11:08:56 -04:00
" Set autocompletion
2014-10-31 17:30:24 -04:00
setlocal omnifunc=go#complete#Complete
2019-03-27 11:08:56 -04:00
if !go#util#has_job()
setlocal omnifunc=go#complete#GocodeComplete
endif
2014-10-31 17:30:24 -04:00
2015-01-18 07:58:28 -05:00
if get(g:, "go_doc_keywordprg_enabled", 1)
2016-06-26 07:12:36 -04:00
" keywordprg doesn't allow to use vim commands, override it
nnoremap <buffer> <silent> K :GoDoc<cr>
2014-10-31 17:30:24 -04:00
endif
2015-01-18 07:58:28 -05:00
if get(g:, "go_def_mapping_enabled", 1)
2016-06-26 07:12:36 -04:00
" these are default Vim mappings, we're overriding them to make them
" useful again for Go source code
nnoremap <buffer> <silent> gd :GoDef<cr>
nnoremap <buffer> <silent> <C-]> :GoDef<cr>
2017-05-26 05:30:32 -04:00
nnoremap <buffer> <silent> <C-LeftMouse> <LeftMouse>:GoDef<cr>
nnoremap <buffer> <silent> g<LeftMouse> <LeftMouse>:GoDef<cr>
2019-03-27 11:08:56 -04:00
nnoremap <buffer> <silent> <C-w><C-]> :<C-u>call go#def#Jump("split", 0)<CR>
nnoremap <buffer> <silent> <C-w>] :<C-u>call go#def#Jump("split", 0)<CR>
2016-06-26 07:12:36 -04:00
nnoremap <buffer> <silent> <C-t> :<C-U>call go#def#StackPop(v:count1)<cr>
2015-01-18 07:58:28 -05:00
endif
2014-10-31 17:30:24 -04:00
2015-01-18 07:58:28 -05:00
if get(g:, "go_textobj_enabled", 1)
2016-06-26 07:12:36 -04:00
onoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
xnoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
2018-06-14 06:31:12 -04:00
onoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
2016-06-26 07:12:36 -04:00
xnoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
2016-03-20 14:01:44 -04:00
2018-06-14 06:31:12 -04:00
onoremap <buffer> <silent> ac :<c-u>call go#textobj#Comment('a')<cr>
xnoremap <buffer> <silent> ac :<c-u>call go#textobj#Comment('a')<cr>
onoremap <buffer> <silent> ic :<c-u>call go#textobj#Comment('i')<cr>
xnoremap <buffer> <silent> ic :<c-u>call go#textobj#Comment('i')<cr>
2016-06-26 07:12:36 -04:00
" Remap ]] and [[ to jump betweeen functions as they are useless in Go
nnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('n', 'next')<cr>
nnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('n', 'prev')<cr>
2016-03-20 14:01:44 -04:00
2016-06-26 07:12:36 -04:00
onoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('o', 'next')<cr>
onoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('o', 'prev')<cr>
2016-03-20 14:01:44 -04:00
2016-06-26 07:12:36 -04:00
xnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('v', 'next')<cr>
xnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('v', 'prev')<cr>
2014-10-31 17:30:24 -04:00
endif
2018-06-14 06:31:12 -04:00
if go#config#AutoTypeInfo() || go#config#AutoSameids()
2016-12-27 09:46:49 -05:00
let &l:updatetime= get(g:, "go_updatetime", 800)
2014-10-31 17:30:24 -04:00
endif
2019-03-08 06:04:56 -05:00
" Autocommands
" ============================================================================
2016-12-27 09:46:49 -05:00
"
2019-03-08 06:04:56 -05:00
augroup vim-go-buffer
autocmd! * <buffer>
2019-03-27 11:08:56 -04:00
" TODO(bc): notify gopls about changes on CursorHold when the buffer is
" modified.
" TODO(bc): notify gopls that the file on disk is correct on BufWritePost
2019-03-08 06:04:56 -05:00
autocmd CursorHold <buffer> call go#auto#auto_type_info()
autocmd CursorHold <buffer> 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 <buffer> call go#auto#echo_go_info()
endif
autocmd BufWritePre <buffer> call go#auto#fmt_autosave()
autocmd BufWritePost <buffer> 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 <buffer> call go#guru#ClearSameIds()
autocmd BufEnter <buffer>
\ if go#config#AutodetectGopath() && !exists('b:old_gopath')
\| let b:old_gopath = exists('$GOPATH') ? $GOPATH : -1
\| let $GOPATH = go#path#Detect()
\| endif
autocmd BufLeave <buffer>
\ if exists('b:old_gopath')
\| if b:old_gopath isnot -1
\| let $GOPATH = b:old_gopath
\| endif
\| unlet b:old_gopath
\| endif
augroup end
2016-12-27 09:46:49 -05:00
2018-12-17 06:28:27 -05:00
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et