blob: f3cae02065e81958b84aab00400cc3771f731f16 [file] [log] [blame]
Bram Moolenaarfb539272014-08-22 19:21:47 +02001" Vim filetype plugin file
2" Language: Go
Phạm Bình An11ab02c2025-03-18 21:05:35 +01003" Maintainer: David Barnett (https://github.com/google/vim-ft-go is archived)
Bram Moolenaarfb539272014-08-22 19:21:47 +02004" 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)
Phạm Bình An11ab02c2025-03-18 21:05:35 +01007" 2025 Mar 18 by Vim Project (use :term for 'keywordprg' #16911)
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +02008" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121)
Bram Moolenaarfb539272014-08-22 19:21:47 +02009
10if exists('b:did_ftplugin')
11 finish
12endif
13let b:did_ftplugin = 1
14
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +020015let s:cpo_save = &cpo
16set cpo&vim
17
Bram Moolenaarfb539272014-08-22 19:21:47 +020018setlocal formatoptions-=t
Phạm Bình An62e82282025-03-07 19:19:31 +010019setlocal formatprg=gofmt
Bram Moolenaarfb539272014-08-22 19:21:47 +020020
21setlocal comments=s1:/*,mb:*,ex:*/,://
22setlocal commentstring=//\ %s
Phạm Bình An62e82282025-03-07 19:19:31 +010023setlocal keywordprg=:GoKeywordPrg
Bram Moolenaarfb539272014-08-22 19:21:47 +020024
Phạm Bình An62e82282025-03-07 19:19:31 +010025command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
26
27let b:undo_ftplugin = 'setl fo< com< cms< fp< kp<'
28 \ . '| delcommand -buffer GoKeywordPrg'
Bram Moolenaarfb539272014-08-22 19:21:47 +020029
markmacode3e07d5a2024-07-16 21:20:34 +020030if get(g:, 'go_recommended_style', 1)
31 setlocal noexpandtab softtabstop=0 shiftwidth=0
32 let b:undo_ftplugin ..= ' | setl et< sts< sw<'
33endif
34
Phạm Bình An62e82282025-03-07 19:19:31 +010035if !exists('*' .. expand('<SID>') .. 'GoKeywordPrg')
36 func! s:GoKeywordPrg()
37 let temp_isk = &l:iskeyword
38 setl iskeyword+=.
39 try
40 let cmd = 'go doc -C ' . shellescape(expand('%:h')) . ' ' . shellescape(expand('<cword>'))
Phạm Bình An11ab02c2025-03-18 21:05:35 +010041 if has('gui_running') || has('nvim')
42 exe 'hor term' cmd
Phạm Bình An62e82282025-03-07 19:19:31 +010043 else
44 exe '!' . cmd
45 endif
46 finally
47 let &l:iskeyword = temp_isk
48 endtry
49 endfunc
50endif
51
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +020052let &cpo = s:cpo_save
53unlet s:cpo_save
54
Bram Moolenaarfb539272014-08-22 19:21:47 +020055" vim: sw=2 sts=2 et