vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

go.vim (2987B)


      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 " 2026 Oct 12 by Vim Project (correctly use shellescape())
     14 
     15 if exists('b:did_ftplugin')
     16   finish
     17 endif
     18 let b:did_ftplugin = 1
     19 
     20 let s:cpo_save = &cpo
     21 set cpo&vim
     22 
     23 setlocal formatoptions-=t
     24 
     25 setlocal comments=s1:/*,mb:*,ex:*/,://
     26 setlocal commentstring=//\ %s
     27 setlocal keywordprg=:GoKeywordPrg
     28 
     29 command! -buffer -nargs=* GoKeywordPrg call s:GoKeywordPrg()
     30 
     31 let b:undo_ftplugin = 'setl fo< com< cms< kp<'
     32                   \ . '| delcommand -buffer GoKeywordPrg'
     33 
     34 if get(g:, 'go_recommended_style',
     35       \ get(g:, 'filetype_recommended_style', 1))
     36   setlocal noexpandtab softtabstop=0 shiftwidth=0
     37   let b:undo_ftplugin .= ' | setl et< sts< sw<'
     38 endif
     39 
     40 if !exists('*' . expand('<SID>') . 'GoKeywordPrg')
     41   func! s:GoKeywordPrg()
     42     let temp_isk = &l:iskeyword
     43     setl iskeyword+=.
     44     try
     45       let cmd = 'go doc -C ' . shellescape(expand('%:h'), 1) . ' ' . shellescape(expand('<cword>'), 1)
     46       if has('gui_running')
     47         exe 'hor term ++shell' cmd
     48       elseif has('nvim')
     49         exe 'hor term' cmd
     50       else
     51         exe '!' . cmd
     52       endif
     53     finally
     54       let &l:iskeyword = temp_isk
     55     endtry
     56   endfunc
     57 endif
     58 
     59 if !exists("no_plugin_maps") && !exists("no_go_maps")
     60   noremap <silent> <buffer> ]] <Cmd>call <SID>GoFindSection('next_start', v:count1)<CR>
     61   noremap <silent> <buffer> ][ <Cmd>call <SID>GoFindSection('next_end', v:count1)<CR>
     62   noremap <silent> <buffer> [[ <Cmd>call <SID>GoFindSection('prev_start', v:count1)<CR>
     63   noremap <silent> <buffer> [] <Cmd>call <SID>GoFindSection('prev_end', v:count1)<CR>
     64   let b:undo_ftplugin .= ''
     65                       \ . "| silent! exe 'unmap <buffer> ]]'"
     66                       \ . "| silent! exe 'unmap <buffer> ]['"
     67                       \ . "| silent! exe 'unmap <buffer> [['"
     68                       \ . "| silent! exe 'unmap <buffer> []'"
     69 endif
     70 
     71 function! <SID>GoFindSection(dir, count)
     72   mark '
     73   let c = a:count
     74   while c > 0
     75     if a:dir == 'next_start'
     76       keepjumps call search('^\(type\|func\)\>', 'W')
     77     elseif a:dir == 'next_end'
     78       keepjumps call search('^}', 'W')
     79     elseif a:dir == 'prev_start'
     80       keepjumps call search('^\(type\|func\)\>', 'bW')
     81     elseif a:dir == 'prev_end'
     82       keepjumps call search('^}', 'bW')
     83     endif
     84     let c -= 1
     85   endwhile
     86 endfunction
     87 
     88 let &cpo = s:cpo_save
     89 unlet s:cpo_save
     90 
     91 " vim: sw=2 sts=2 et