0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
Phạm Bình An 11ab02c819
runtime(go): use :term for keywordprg for nvim/gvim
Problem:
- The document from `go doc` can be very long, and you can scroll if
  using `!` to run shell command in Gvim.
- I realize that I didn't fully mimic behavior of default keywordprg
  in Nvim in the last commit.

Solution:
- Use builtin terminal for keywordprg in Gvim
- In Nvim (both TUI and GUI), it should mimic the behavior of Vim
  `:term`, `:Man`, and `:help`

closes: #16911

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Phạm Bình An <phambinhanctb2004@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-03-18 21:05:35 +01:00

49 lines
1.3 KiB
VimL

" Vim filetype plugin file
" Language: Go
" Maintainer: David Barnett (https://github.com/google/vim-ft-go is archived)
" Last Change: 2014 Aug 16
" 2024 Jul 16 by Vim Project (add recommended indent style)
" 2025 Mar 07 by Vim Project (add formatprg and keywordprg option #16804)
" 2025 Mar 18 by Vim Project (use :term for 'keywordprg' #16911)
if exists('b:did_ftplugin')
finish
endif
let b:did_ftplugin = 1
setlocal formatoptions-=t
setlocal formatprg=gofmt
setlocal comments=s1:/*,mb:*,ex:*/,://
setlocal commentstring=//\ %s
setlocal keywordprg=:GoKeywordPrg
command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
let b:undo_ftplugin = 'setl fo< com< cms< fp< kp<'
\ . '| delcommand -buffer GoKeywordPrg'
if get(g:, 'go_recommended_style', 1)
setlocal noexpandtab softtabstop=0 shiftwidth=0
let b:undo_ftplugin ..= ' | setl et< sts< sw<'
endif
if !exists('*' .. expand('<SID>') .. 'GoKeywordPrg')
func! s:GoKeywordPrg()
let temp_isk = &l:iskeyword
setl iskeyword+=.
try
let cmd = 'go doc -C ' . shellescape(expand('%:h')) . ' ' . shellescape(expand('<cword>'))
if has('gui_running') || has('nvim')
exe 'hor term' cmd
else
exe '!' . cmd
endif
finally
let &l:iskeyword = temp_isk
endtry
endfunc
endif
" vim: sw=2 sts=2 et