blob: b83db424bd79950e79e5eba355123509f6746673 [file] [log] [blame]
Bram Moolenaarfb539272014-08-22 19:21:47 +02001" Vim filetype plugin file
2" Language: Go
3" Maintainer: David Barnett (https://github.com/google/vim-ft-go)
4" Last Change: 2014 Aug 16
markmacode3e07d5a2024-07-16 21:20:34 +02005" 2024 Jul 16 by Vim Project (add recommended indent style)
Phạm Bình An62e82282025-03-07 19:19:31 +01006" 2025 Mar 07 by Vim Project (add formatprg and keywordprg option #16804)
Bram Moolenaarfb539272014-08-22 19:21:47 +02007
8if exists('b:did_ftplugin')
9 finish
10endif
11let b:did_ftplugin = 1
12
13setlocal formatoptions-=t
Phạm Bình An62e82282025-03-07 19:19:31 +010014setlocal formatprg=gofmt
Bram Moolenaarfb539272014-08-22 19:21:47 +020015
16setlocal comments=s1:/*,mb:*,ex:*/,://
17setlocal commentstring=//\ %s
Phạm Bình An62e82282025-03-07 19:19:31 +010018setlocal keywordprg=:GoKeywordPrg
Bram Moolenaarfb539272014-08-22 19:21:47 +020019
Phạm Bình An62e82282025-03-07 19:19:31 +010020command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
21
22let b:undo_ftplugin = 'setl fo< com< cms< fp< kp<'
23 \ . '| delcommand -buffer GoKeywordPrg'
Bram Moolenaarfb539272014-08-22 19:21:47 +020024
markmacode3e07d5a2024-07-16 21:20:34 +020025if get(g:, 'go_recommended_style', 1)
26 setlocal noexpandtab softtabstop=0 shiftwidth=0
27 let b:undo_ftplugin ..= ' | setl et< sts< sw<'
28endif
29
Phạm Bình An62e82282025-03-07 19:19:31 +010030if !exists('*' .. expand('<SID>') .. 'GoKeywordPrg')
31 func! s:GoKeywordPrg()
32 let temp_isk = &l:iskeyword
33 setl iskeyword+=.
34 try
35 let cmd = 'go doc -C ' . shellescape(expand('%:h')) . ' ' . shellescape(expand('<cword>'))
36 if has('nvim')
37 exe "term" cmd
38 startinsert
39 tmap <buffer> <Esc> <Cmd>call jobstop(&channel) <Bar> bdelete<CR>
40 else
41 exe '!' . cmd
42 endif
43 finally
44 let &l:iskeyword = temp_isk
45 endtry
46 endfunc
47endif
48
Bram Moolenaarfb539272014-08-22 19:21:47 +020049" vim: sw=2 sts=2 et