go.vim 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. " Copyright 2013 The Go Authors. All rights reserved.
  2. " Use of this source code is governed by a BSD-style
  3. " license that can be found in the LICENSE file.
  4. "
  5. " go.vim: Vim filetype plugin for Go.
  6. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. let b:undo_ftplugin = "setl fo< com< cms<"
  11. setlocal formatoptions-=t
  12. setlocal comments=s1:/*,mb:*,ex:*/,://
  13. setlocal commentstring=//\ %s
  14. setlocal noexpandtab
  15. compiler go
  16. " Set gocode completion
  17. setlocal omnifunc=go#complete#Complete
  18. if get(g:, "go_doc_keywordprg_enabled", 1)
  19. " keywordprg doesn't allow to use vim commands, override it
  20. nnoremap <buffer> <silent> K :GoDoc<cr>
  21. endif
  22. if get(g:, "go_def_mapping_enabled", 1)
  23. " these are default Vim mappings, we're overriding them to make them
  24. " useful again for Go source code
  25. nnoremap <buffer> <silent> gd :GoDef<cr>
  26. nnoremap <buffer> <silent> <C-]> :GoDef<cr>
  27. nnoremap <buffer> <silent> <C-LeftMouse> <LeftMouse>:GoDef<cr>
  28. nnoremap <buffer> <silent> g<LeftMouse> <LeftMouse>:GoDef<cr>
  29. nnoremap <buffer> <silent> <C-w><C-]> :<C-u>call go#def#Jump("split")<CR>
  30. nnoremap <buffer> <silent> <C-w>] :<C-u>call go#def#Jump("split")<CR>
  31. nnoremap <buffer> <silent> <C-t> :<C-U>call go#def#StackPop(v:count1)<cr>
  32. endif
  33. if get(g:, "go_textobj_enabled", 1)
  34. onoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
  35. onoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
  36. xnoremap <buffer> <silent> af :<c-u>call go#textobj#Function('a')<cr>
  37. xnoremap <buffer> <silent> if :<c-u>call go#textobj#Function('i')<cr>
  38. " Remap ]] and [[ to jump betweeen functions as they are useless in Go
  39. nnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('n', 'next')<cr>
  40. nnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('n', 'prev')<cr>
  41. onoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('o', 'next')<cr>
  42. onoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('o', 'prev')<cr>
  43. xnoremap <buffer> <silent> ]] :<c-u>call go#textobj#FunctionJump('v', 'next')<cr>
  44. xnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('v', 'prev')<cr>
  45. endif
  46. if get(g:, "go_auto_type_info", 0) || get(g:, "go_auto_sameids", 0)
  47. let &l:updatetime= get(g:, "go_updatetime", 800)
  48. endif
  49. " NOTE(arslan): experimental, disabled by default, doesn't work well. No
  50. " documentation as well. If anyone feels adventurous, enable the following and
  51. " try to search for Go identifiers ;)
  52. "
  53. " if get(g:, "go_sameid_search_enabled", 0)
  54. " autocmd FileType go nnoremap <buffer> <silent> * :<c-u>call Sameids_search(0)<CR>
  55. " autocmd FileType go nnoremap <buffer> <silent> # :<c-u>call Sameids_search(1)<CR>
  56. " autocmd FileType go nnoremap <buffer> <silent> n :<c-u>call Sameids_repeat(0)<CR>
  57. " autocmd FileType go nnoremap <buffer> <silent> N :<c-u>call Sameids_repeat(1)<CR>
  58. " autocmd FileType go cabbrev nohlsearch <C-r>=Sameids_nohlsearch()<CR>
  59. " endif
  60. " " mode 0: next 1: prev
  61. " function! Sameids_repeat(mode)
  62. " let matches = getmatches()
  63. " if empty(matches)
  64. " return
  65. " endif
  66. " let cur_offset = go#util#OffsetCursor()
  67. " " reverse list to make it easy to find the prev occurrence
  68. " if a:mode
  69. " call reverse(matches)
  70. " endif
  71. " for m in matches
  72. " if !has_key(m, "group")
  73. " return
  74. " endif
  75. " if m.group != "goSameId"
  76. " return
  77. " endif
  78. " let offset = go#util#Offset(m.pos1[0], m.pos1[1])
  79. " if a:mode && cur_offset > offset
  80. " call cursor(m.pos1[0], m.pos1[1])
  81. " return
  82. " elseif !a:mode && cur_offset < offset
  83. " call cursor(m.pos1[0], m.pos1[1])
  84. " return
  85. " endif
  86. " endfor
  87. " " reached start/end, jump to the end/start
  88. " let initial_match = matches[0]
  89. " if !has_key(initial_match, "group")
  90. " return
  91. " endif
  92. " if initial_match.group != "goSameId"
  93. " return
  94. " endif
  95. " call cursor(initial_match.pos1[0], initial_match.pos1[1])
  96. " endfunction
  97. " function! Sameids_search(mode)
  98. " call go#guru#SameIds()
  99. " call Sameids_repeat(a:mode)
  100. " endfunction
  101. " function! Sameids_nohlsearch()
  102. " call go#guru#ClearSameIds()
  103. " return "nohlsearch"
  104. " endfunction
  105. " vim: sw=2 ts=2 et