Last active
February 7, 2023 06:28
-
-
Save joshuarubin/5d1f7c279160c4769feca8a6000b6da3 to your computer and use it in GitHub Desktop.
Minimal neovim configuration for go (golang)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Minimal neovim configuration for go | |
" | |
" deoplete requires neovim, so this will not work with regular vim | |
" | |
" prereqs: | |
" - neovim | |
" - neovim python3 (pip3 install --upgrade neovim) | |
" | |
" includes: | |
" - syntax checking on save (using neomake, go and gometalinter) | |
" - goimports on save (using vim-go) | |
" - auto-completion (using deoplete) | |
" | |
" First install vim-plug: | |
" curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs \ | |
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
" | |
" Then save this file as ~/.config/nvim/init.vim | |
" Note: Skip initialization for vim-tiny or vim-small. | |
if 0 | endif | |
if &compatible | |
set nocompatible | |
endif | |
let g:mapleader = "," | |
" deoplete | |
set completeopt=longest,menuone " auto complete setting | |
let g:deoplete#enable_at_startup = 1 | |
let g:deoplete#enable_smart_case = 1 | |
let g:deoplete#auto_complete_start_length = 1 | |
let g:deoplete#keyword_patterns = {} | |
let g:deoplete#keyword_patterns['default'] = '\h\w*' | |
let g:deoplete#omni#input_patterns = {} | |
let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const'] | |
let g:deoplete#sources#go#align_class = 1 | |
" neomake | |
autocmd BufWritePost * Neomake | |
let g:neomake_error_sign = {'text': '✖', 'texthl': 'NeomakeErrorSign'} | |
let g:neomake_warning_sign = {'text': '∆', 'texthl': 'NeomakeWarningSign'} | |
let g:neomake_message_sign = {'text': '➤', 'texthl': 'NeomakeMessageSign'} | |
let g:neomake_info_sign = {'text': 'ℹ', 'texthl': 'NeomakeInfoSign'} | |
let g:neomake_go_enabled_makers = [ 'go', 'gometalinter' ] | |
let g:neomake_go_gometalinter_maker = { | |
\ 'args': [ | |
\ '--tests', | |
\ '--enable-gc', | |
\ '--concurrency=3', | |
\ '--fast', | |
\ '-D', 'aligncheck', | |
\ '-D', 'dupl', | |
\ '-D', 'gocyclo', | |
\ '-D', 'gotype', | |
\ '-E', 'errcheck', | |
\ '-E', 'misspell', | |
\ '-E', 'unused', | |
\ '%:p:h', | |
\ ], | |
\ 'append_file': 0, | |
\ 'errorformat': | |
\ '%E%f:%l:%c:%trror: %m,' . | |
\ '%W%f:%l:%c:%tarning: %m,' . | |
\ '%E%f:%l::%trror: %m,' . | |
\ '%W%f:%l::%tarning: %m' | |
\ } | |
" vim-go | |
let g:go_def_mapping_enabled = 0 | |
let g:go_fmt_command = 'goimports' | |
let g:go_fmt_fail_silently = 1 | |
let g:go_term_enabled = 1 | |
" use real tabs in .go files, not spaces | |
autocmd FileType go setlocal shiftwidth=4 tabstop=4 softtabstop=4 noexpandtab | |
" plugins | |
call plug#begin() | |
Plug 'neomake/neomake' | |
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } | |
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } | |
Plug 'zchee/deoplete-go', { 'do': 'make' } | |
" Add plugins to &runtimepath | |
call plug#end() | |
" install missing plugins on start | |
autocmd VimEnter * | |
\ if !empty(filter(copy(g:plugs), '!isdirectory(v:val.dir)')) | |
\| PlugInstall | |
\| endif | |
call deoplete#custom#set('_', 'converters', | |
\ ['converter_auto_paren', | |
\ 'converter_auto_delimiter', | |
\ 'converter_remove_overlap']) | |
" mappings | |
" deoplete | |
imap <expr> <tab> pumvisible() ? "\<c-n>" : "\<tab>" | |
imap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<tab>" | |
imap <expr> <cr> pumvisible() ? deoplete#close_popup() : "\<cr>" | |
" vim-go mappings | |
autocmd FileType go nmap <buffer> <leader>r <plug>(go-run) | |
autocmd FileType go nmap <buffer> <leader>b <plug>(go-build) | |
autocmd FileType go nmap <buffer> <leader>t <plug>(go-test) | |
autocmd FileType go nmap <buffer> <leader>e <plug>(go-rename) | |
autocmd FileType go nmap <buffer> gd <plug>(go-def-vertical) | |
autocmd FileType go nmap <buffer> <c-]> <plug>(go-def-vertical) | |
autocmd FileType go nmap <buffer> <leader>i <plug>(go-info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work anymore ... deprecated warnings and after safe I got an error