blob: 57fc73cd13151456b210f9b1f6a088ff61b39ee2 [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)
Bram Moolenaarfb539272014-08-22 19:21:47 +02008
9if exists('b:did_ftplugin')
10 finish
11endif
12let b:did_ftplugin = 1
13
14setlocal formatoptions-=t
Phạm Bình An62e82282025-03-07 19:19:31 +010015setlocal formatprg=gofmt
Bram Moolenaarfb539272014-08-22 19:21:47 +020016
17setlocal comments=s1:/*,mb:*,ex:*/,://
18setlocal commentstring=//\ %s
Phạm Bình An62e82282025-03-07 19:19:31 +010019setlocal keywordprg=:GoKeywordPrg
Bram Moolenaarfb539272014-08-22 19:21:47 +020020
Phạm Bình An62e82282025-03-07 19:19:31 +010021command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
22
23let b:undo_ftplugin = 'setl fo< com< cms< fp< kp<'
24 \ . '| delcommand -buffer GoKeywordPrg'
Bram Moolenaarfb539272014-08-22 19:21:47 +020025
markmacode3e07d5a2024-07-16 21:20:34 +020026if get(g:, 'go_recommended_style', 1)
27 setlocal noexpandtab softtabstop=0 shiftwidth=0
28 let b:undo_ftplugin ..= ' | setl et< sts< sw<'
29endif
30
Phạm Bình An62e82282025-03-07 19:19:31 +010031if !exists('*' .. expand('<SID>') .. 'GoKeywordPrg')
32 func! s:GoKeywordPrg()
33 let temp_isk = &l:iskeyword
34 setl iskeyword+=.
35 try
36 let cmd = 'go doc -C ' . shellescape(expand('%:h')) . ' ' . shellescape(expand('<cword>'))
Phạm Bình An11ab02c2025-03-18 21:05:35 +010037 if has('gui_running') || has('nvim')
38 exe 'hor term' cmd
Phạm Bình An62e82282025-03-07 19:19:31 +010039 else
40 exe '!' . cmd
41 endif
42 finally
43 let &l:iskeyword = temp_isk
44 endtry
45 endfunc
46endif
47
Bram Moolenaarfb539272014-08-22 19:21:47 +020048" vim: sw=2 sts=2 et