neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

go.vim (2765B)


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