robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40472 from zeertzjq/vim-1f337327945732ed7

master
2.8 KiB88 linesraw
1" Vim filetype plugin file
2" Language:	Go
3" Maintainer:	David Barnett (https://github.com/google/vim-ft-go is archived)
4" Last Change:	2014 Aug 16
5" 2024 Jul 16 by Vim Project (add recommended indent style)
6" 2025 Mar 07 by Vim Project (add formatprg and keywordprg option #16804)
7" 2025 Mar 18 by Vim Project (use :term for 'keywordprg' #16911)
8" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121)
9" 2025 Jul 02 by Vim Project (add section movement mappings #17641)
10" 2025 Jul 05 by Vim Project (update b:undo_ftplugin #17664)
11" 2026 Feb 13 by Vim Project (remove formatprg #19108)
12" 2026 Jun 27 by Vim Project (normalize recommended style guard)
13
14if exists('b:did_ftplugin')
15  finish
16endif
17let b:did_ftplugin = 1
18
19let s:cpo_save = &cpo
20set cpo&vim
21
22setlocal formatoptions-=t
23
24setlocal comments=s1:/*,mb:*,ex:*/,://
25setlocal commentstring=//\ %s
26setlocal keywordprg=:GoKeywordPrg
27
28command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
29
30let b:undo_ftplugin = 'setl fo< com< cms< kp<'
31                  \ . '| delcommand -buffer GoKeywordPrg'
32
33if get(g:, 'go_recommended_style',
34      \ get(g:, 'filetype_recommended_style', 1))
35  setlocal noexpandtab softtabstop=0 shiftwidth=0
36  let b:undo_ftplugin .= ' | setl et< sts< sw<'
37endif
38
39if !exists('*' . expand('<SID>') . 'GoKeywordPrg')
40  func! s:GoKeywordPrg()
41    let temp_isk = &l:iskeyword
42    setl iskeyword+=.
43    try
44      let cmd = 'go doc -C ' . shellescape(expand('%:h')) . ' ' . shellescape(expand('<cword>'))
45      if has('gui_running') || has('nvim')
46        exe 'hor term' cmd
47      else
48        exe '!' . cmd
49      endif
50    finally
51      let &l:iskeyword = temp_isk
52    endtry
53  endfunc
54endif
55
56if !exists("no_plugin_maps") && !exists("no_go_maps")
57  noremap <silent> <buffer> ]] <Cmd>call <SID>GoFindSection('next_start', v:count1)<CR>
58  noremap <silent> <buffer> ][ <Cmd>call <SID>GoFindSection('next_end', v:count1)<CR>
59  noremap <silent> <buffer> [[ <Cmd>call <SID>GoFindSection('prev_start', v:count1)<CR>
60  noremap <silent> <buffer> [] <Cmd>call <SID>GoFindSection('prev_end', v:count1)<CR>
61  let b:undo_ftplugin .= ''
62                      \ . "| silent! exe 'unmap <buffer> ]]'"
63                      \ . "| silent! exe 'unmap <buffer> ]['"
64                      \ . "| silent! exe 'unmap <buffer> [['"
65                      \ . "| silent! exe 'unmap <buffer> []'"
66endif
67
68function! <SID>GoFindSection(dir, count)
69  mark '
70  let c = a:count
71  while c > 0
72    if a:dir == 'next_start'
73      keepjumps call search('^\(type\|func\)\>', 'W')
74    elseif a:dir == 'next_end'
75      keepjumps call search('^}', 'W')
76    elseif a:dir == 'prev_start'
77      keepjumps call search('^\(type\|func\)\>', 'bW')
78    elseif a:dir == 'prev_end'
79      keepjumps call search('^}', 'bW')
80    endif
81    let c -= 1
82  endwhile
83endfunction
84
85let &cpo = s:cpo_save
86unlet s:cpo_save
87
88" vim: sw=2 sts=2 et