Skip to content

Commit

Permalink
Add golang config and linting with ALE
Browse files Browse the repository at this point in the history
  • Loading branch information
owodunni committed Dec 29, 2020
1 parent d3c170f commit 6397c20
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
103 changes: 102 additions & 1 deletion init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ set autoindent " indent a new line the same amount as the line just
set number " add line numbers
set wildmode=longest,list " get bash-like tab completions
set cc=80 " set an 80 column border for good coding style

autocmd Filetype html setlocal ts=2 sw=2 expandtab
autocmd Filetype python setlocal ts=2 sw=2 expandtab
autocmd Filetype golang setlocal ts=4 sw=4 sts=0 noexpandtab

filetype plugin indent on " allows auto-indenting depending on file type
syntax on " syntax highlighting

Expand Down Expand Up @@ -64,10 +69,16 @@ Plug 'tpope/vim-fugitive'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

Plug 'dense-analysis/ale'

"These plugins gave me funcy behaviours might have to disable these when not
".js or .sol files
"Plug 'pangloss/vim-javascript'
"Plug 'TovarishFin/vim-solidity'
Plug 'tomlion/vim-solidity'
Plug 'sohkai/syntastic-local-solhint'

" Golang
Plug 'fatih/vim-go'
call plug#end()

" airline
Expand All @@ -81,6 +92,14 @@ let NERDTreeShowHidden=1
" jedi-vim
let g:jedi#completions_enabled = 0
let g:jedi#use_splits_not_buffers = "right"
let g:jedi#popup_on_dot = 0
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = "<leader>d"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#rename_command = "<leader>r"
let g:jedi#show_call_signatures = "0"
let g:jedi#smart_auto_mappings = 0

" deoplete
inoremap <expr> <C-j> pumvisible() ? "\<C-n>" : "\<C-j>"
Expand Down Expand Up @@ -115,3 +134,85 @@ set clipboard=unnamedplus
" set spellfile=file/in/version/control/en.utf-8.add
set spell
set spelllang=en_us

" ale
let g:ale_linters = {}

"*****************************************************************************
"" Custom configs
"*****************************************************************************

" go
" vim-go
" 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#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction

let g:go_list_type = "quickfix"
let g:go_fmt_command = "goimports"
let g:go_fmt_fail_silently = 1

let g:go_highlight_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_build_constraints = 1
let g:go_highlight_structs = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_space_tab_error = 0
let g:go_highlight_array_whitespace_error = 0
let g:go_highlight_trailing_whitespace_error = 0
let g:go_highlight_extra_types = 1

autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=4

augroup completion_preview_close
autocmd!
if v:version > 703 || v:version == 703 && has('patch598')
autocmd CompleteDone * if !&previewwindow && &completeopt =~ 'preview' | silent! pclose | endif
endif
augroup END

augroup go

au!
au Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
au Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
au Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
au Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')

au FileType go nmap <Leader>dd <Plug>(go-def-vertical)
au FileType go nmap <Leader>dv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>db <Plug>(go-doc-browser)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <Leader>gt <Plug>(go-coverage-toggle)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <silent> <Leader>l <Plug>(go-metalinter)
au FileType go nmap <C-g> :GoDecls<cr>
au FileType go nmap <leader>dr :GoDeclsDir<cr>
au FileType go imap <C-g> <esc>:<C-u>GoDecls<cr>
au FileType go imap <leader>dr <esc>:<C-u>GoDeclsDir<cr>
au FileType go nmap <leader>rb :<C-u>call <SID>build_go_files()<CR>
augroup END

" ale
:call extend(g:ale_linters, {
\"go": ['golint', 'go vet'], })

" python
" ale
:call extend(g:ale_linters, {
\'python': ['flake8'], })

"*****************************************************************************
"*****************************************************************************
7 changes: 7 additions & 0 deletions zshrc_profile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || pr
source $HOME/.config/nvim/alias.sh
source $HOME/.config/nvim/nvim_profile
source $HOME/.local/venv/bin/activate


export PATH=$PATH:/usr/local/go/bin

export GOPATH=$HOME/.local/golib
export PATH=$PATH:$GOPATH/bin
export GOPATH=$GOPATH:$HOME/Prog/go

0 comments on commit 6397c20

Please sign in to comment.