Skip to content

Instantly share code, notes, and snippets.

@mtrovo
Created August 2, 2017 09:26
Show Gist options
  • Save mtrovo/668111b30ee95629d4957cac152527c1 to your computer and use it in GitHub Desktop.
Save mtrovo/668111b30ee95629d4957cac152527c1 to your computer and use it in GitHub Desktop.
my vim-go mappings
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#cmd#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
augroup go
autocmd!
autocmd FileType go nmap <silent> <Leader>v <Plug>(go-def-vertical)
autocmd FileType go nmap <silent> <Leader>s <Plug>(go-def-split)
autocmd FileType go nmap <silent> <Leader>i <Plug>(go-info)
autocmd FileType go nmap <silent> <Leader>l <Plug>(go-metalinter)
autocmd FileType go nmap <silent> <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <silent> <leader>t <Plug>(go-test)
autocmd FileType go nmap <silent> <leader>r <Plug>(go-run)
autocmd FileType go nmap <silent> <leader>e <Plug>(go-install)
autocmd FileType go nmap <silent> <Leader>d <Plug>(go-doc)
autocmd FileType go nmap <silent> <Leader>c <Plug>(go-coverage-toggle)
" I like these more!
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment