File: go.vim

package info (click to toggle)
vim 2%3A9.1.1882-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,504 kB
  • sloc: ansic: 432,444; cpp: 6,371; makefile: 4,596; sh: 2,387; java: 2,312; xml: 2,099; python: 1,559; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; sed: 8; csh: 6
file content (86 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
" 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)
" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121)
" 2025 Jul 02 by Vim Project (add section movement mappings #17641)
" 2025 Jul 05 by Vim Project (update b:undo_ftplugin #17664)

if exists('b:did_ftplugin')
  finish
endif
let b:did_ftplugin = 1

let s:cpo_save = &cpo
set cpo&vim

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

if !exists("no_plugin_maps") && !exists("no_go_maps")
  noremap <silent> <buffer> ]] <Cmd>call <SID>GoFindSection('next_start', v:count1)<CR>
  noremap <silent> <buffer> ][ <Cmd>call <SID>GoFindSection('next_end', v:count1)<CR>
  noremap <silent> <buffer> [[ <Cmd>call <SID>GoFindSection('prev_start', v:count1)<CR>
  noremap <silent> <buffer> [] <Cmd>call <SID>GoFindSection('prev_end', v:count1)<CR>
  let b:undo_ftplugin .= ''
                      \ . "| silent! exe 'unmap <buffer> ]]'"
                      \ . "| silent! exe 'unmap <buffer> ]['"
                      \ . "| silent! exe 'unmap <buffer> [['"
                      \ . "| silent! exe 'unmap <buffer> []'"
endif

function! <SID>GoFindSection(dir, count)
  mark '
  let c = a:count
  while c > 0
    if a:dir == 'next_start'
      keepjumps call search('^\(type\|func\)\>', 'W')
    elseif a:dir == 'next_end'
      keepjumps call search('^}', 'W')
    elseif a:dir == 'prev_start'
      keepjumps call search('^\(type\|func\)\>', 'bW')
    elseif a:dir == 'prev_end'
      keepjumps call search('^}', 'bW')
    endif
    let c -= 1
  endwhile
endfunction

let &cpo = s:cpo_save
unlet s:cpo_save

" vim: sw=2 sts=2 et