Skip to content

Instantly share code, notes, and snippets.

@vicendominguez
Last active June 1, 2021 20:24
Show Gist options
  • Save vicendominguez/c315a40e2cf2d260dee8e45646db25f5 to your computer and use it in GitHub Desktop.
Save vicendominguez/c315a40e2cf2d260dee8e45646db25f5 to your computer and use it in GitHub Desktop.
simple and basic vimrc for golang using vim-plug and vim-go
" Plugins
" external tool dependencies:
" - ripgrep
" - bat
" remember: :PlugInstall
call plug#begin()
Plug 'fatih/vim-go'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'fatih/molokai'
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
" FZF Vim Integration.
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Nice splitting / joining.
Plug 'AndrewRadev/splitjoin.vim'
" NERD Commenter plugin.V
Plug 'scrooloose/nerdcommenter'
" NERD Tree
Plug 'preservim/nerdtree'
call plug#end()
filetype plugin indent on
set autowrite
set number
set tabstop=2 " Global tab width.
set shiftwidth=2 " And again, related.
set expandtab " Use spaces instead of tabs
set laststatus=2 " Show the status line all the time
set splitbelow " More natural split
set splitright " More natural split
" Colors
let g:rehash256 = 1
let g:molokai_original = 1
colorscheme molokai
" Go syntax highlighting
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_operators = 1
" Auto formatting and importing
let g:go_fmt_autosave = 1
let g:go_fmt_command = "goimports"
" Status line types/signatures
let g:go_auto_type_info = 1
set updatetime=100
" 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
" Map keys for most used commands.
" Ex: `\b` for building, `\r` for running and `\t` for running test.
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
" Returned types
autocmd FileType go nmap <Leader>i <Plug>(go-info)
let g:go_auto_type_info = 1
" Automatic autocomplete after write .
au filetype go inoremap <buffer> . .<C-x><C-o>
" NERD Commenter plugin.V
" Create default mappings
let g:NERDCreateDefaultMappings = 1
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" FZF + ripgrep
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
" NerdTree settings
" Toggle NerdTree with Ctrl+N
map <C-n> :NERDTreeToggle<CR>
" Open NerdTree automatically on startup.
" Also focus the *previous* window, i.e. the main window!
" autocmd vimenter * NERDTree | wincmd p
" Show or hide hidden files.
let NERDTreeShowHidden=1
" But still ignore some normally not needed files.
let g:NERDTreeIgnore=['\.git$[[dir]]', 'node_modules$[[dir]]', '\.nyc_output$[[dir]]']
" Show the current file in NERDTree.
map <leader>t :NERDTreeFind<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment