Skip to content

Instantly share code, notes, and snippets.

@bihe
Created November 17, 2019 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bihe/1e4bed80f1ec82a8d4b44d9bdcb441b7 to your computer and use it in GitHub Desktop.
Save bihe/1e4bed80f1ec82a8d4b44d9bdcb441b7 to your computer and use it in GitHub Desktop.
neovim config for golang
"" --------------------------------------------------------------------------
"" settings and intro to turn vim into a golang IDE
"" https://octetz.com/posts/vim-as-go-ide
"" --------------------------------------------------------------------------
call plug#begin('~/.vim/plugged')
" < Other Plugins, if they exist >
Plug 'NLKNguyen/papercolor-theme'
Plug 'fatih/vim-go'
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'}
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'itchyny/lightline.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'scrooloose/nerdtree'
Plug 'editorconfig/editorconfig-vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
call plug#end()
" -------------------------------------------------------------------------------------------------
" basic nvim settings
" -------------------------------------------------------------------------------------------------
" aesthetics
set t_Co=256
set background=dark
colorscheme PaperColor
" basics
filetype on
filetype plugin on
filetype indent on
syn on
set nu
set cursorline
" navigate tabs
nnoremap H gT
nnoremap L gt
let mapleader = ','
set showcmd
nnoremap <silent> <leader><up> :res +5<CR>
nnoremap <silent> <leader><down> :res -5<CR>
nnoremap <silent> <leader><right> :vertical resize +5<CR>
nnoremap <silent> <leader><left> :vertical resize -5<CR>
" -------------------------------------------------------------------------------------------------
" coc.nvim default settings
" -------------------------------------------------------------------------------------------------
" if hidden is not set, TextEdit might fail.
set hidden
" Better display for messages
set cmdheight=2
" Smaller updatetime for CursorHold & CursorHoldI
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use `[c` and `]c` to navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use U to show documentation in preview window
nnoremap <silent> U :call <SID>show_documentation()<CR>
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
vmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
" -------------------------------------------------------------------------------------------------
" go-vim settings
" -------------------------------------------------------------------------------------------------
" disable vim-go :GoDef short cut (gd)
" this is handled by LanguageClient [LC]
let g:go_def_mapping_enabled = 0
let g:go_fmt_command = "goimports"
au FileType go nnoremap <F8> :GoCoverageToggle -short<cr>
au FileType go nnoremap <S-F6> :GoBuild<cr>
au FileType go nnoremap <leader><F6> :GoTestCompile<cr>
au FileType go nnoremap <leader><F9> :GoDebugBreakpoint<cr>
au FileType go nnoremap <S-F5> :GoDebugStart<cr>
au FileType go nnoremap <leader><F5> :GoDebugTest<cr>
au FileType go nnoremap <F5> :GoDebugContinue<cr>
au FileType go nnoremap <F10> :GoDebugNext<cr>
au FileType go nnoremap <F11> :GoDebugStep<cr>
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" let g:go_highlight_build_constraints = 1
" let g:go_highlight_extra_types = 1
" let g:go_highlight_fields = 1
" let g:go_highlight_functions = 1
" let g:go_highlight_methods = 1
" let g:go_highlight_operators = 1
" let g:go_highlight_structs = 1
" let g:go_highlight_types = 1
" ---------------------------------------------------------------------------
" Fuzzy finding
" ---------------------------------------------------------------------------
map f :Files<CR>
" ---------------------------------------------------------------------------
" NerdTree
" ---------------------------------------------------------------------------
:nnoremap <C-g> :NERDTreeToggle<CR>
" lightline
let g:lightline = {
\ 'colorscheme': 'powerline',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ },
\ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment