Skip to content

Instantly share code, notes, and snippets.

@nstogner
Last active October 2, 2019 13:15
Show Gist options
  • Save nstogner/d13fdecbc32090a7c9cbed6f606d0b09 to your computer and use it in GitHub Desktop.
Save nstogner/d13fdecbc32090a7c9cbed6f606d0b09 to your computer and use it in GitHub Desktop.
nvim
" ~/.config/nvim/init.vim
call plug#begin('~/.local/share/nvim/plugged')
Plug 'NLKNguyen/papercolor-theme' " Color scheme
Plug 'fatih/vim-go' " Go development
Plug 'scrooloose/nerdtree' " Sidebar nav
Plug 'ctrlpvim/ctrlp.vim' " Fuzzy finder nav
Plug 'easymotion/vim-easymotion' " In-file nav
" Autocomplete
" NOTE: First run:
" pip2 install --upgrade neovim
" pip3 install --upgrade neovim
Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.local/share/nvim/plugged/gocode/vim/symlink.sh' }
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'zchee/deoplete-go', { 'do': 'make'}
Plug 'SirVer/ultisnips' " Snippets
call plug#end()
" Stop annoying preview window
set completeopt-=preview
" esc in insert mode
inoremap kj <esc>
" esc in command mode
cnoremap kj <C-C>
" Note: In command mode mappings to esc run the command for some odd
" historical vi compatibility reason. We use the alternate method of
" existing which is Ctrl-C
xnoremap kj <esc>
" Map the leader to a comma
let mapleader = ","
" Paper color scheme
set background=light
colorscheme PaperColor
set number " Show line numbers
set autowrite " Write file on build
set clipboard+=unnamedplus " Use the system clipboard
" Workaround for weird character bug
let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 0
set guicursor=
if has('nvim')
" Enable deoplete on startup
let g:deoplete#enable_at_startup = 1
endif
" Disable deoplete when in multi cursor mode
function! Multiple_cursors_before()
let b:deoplete_disable_auto_complete = 1
endfunction
function! Multiple_cursors_after()
let b:deoplete_disable_auto_complete = 0
endfunction
" Snippets
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" Ctrl-p
set wildignore+=*/vendor/*
" Nerd Tree (ctrl-e)
map <C-e> :NERDTreeToggle<CR>
" Close on file open
let g:NERDTreeQuitOnOpen = 1
" Easymotion (space-b, space-w, space-f, space-F)
map <SPACE> <Plug>(easymotion-prefix)
" Go to next error
map <C-n> :cnext<CR>
" Go to prev error
map <C-m> :cprevious<CR>
" Close quickfix window (error box)
nnoremap <leader>a :cclose<CR>
" For conceal markers.
if has('conceal')
set conceallevel=2 concealcursor=niv
endif
" GO SETTINGS
" gd - GoDef
" ctrl-t - GoDefPop (where gd was called)
" ctrl-n - Next error (:cnext)
" ctrl-m - Prev error (:cprevious)
" K - GoDoc
let g:go_bin_path = $GOPATH . '/bin'
" Only use quickfix window (not location lists)
let g:go_list_type = "quickfix"
" Auto import
let g:go_fmt_command = "goimports"
" Show matching identifiers on hover
" let g:go_auto_sameids = 1
" Show type info on hover
" let g:go_auto_type_info = 1
" Show type info after 100ms instead of default 800ms
set updatetime=100
" Pretty colors
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
" Tab size
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
" Linting
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
let g:go_metalinter_deadline = "5s"
" Only call fast linters on save
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
" Call linting on save
let g:go_metalinter_autosave = 0
" QUICK GO COMMANDS
autocmd FileType go nmap <leader>d <Plug>(go-doc-browser)
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>e <Plug>(go-rename)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <leader>i <Plug>(go-implements)
autocmd FileType go nmap <leader>f <Plug>(go-referrers)
" 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
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
autocmd Filetype yaml setlocal ts=2 sts=2 sw=2
autocmd Filetype python setlocal ts=2 sts=2 sw=2
autocmd Filetype html setlocal ts=2 sts=2 sw=2
autocmd Filetype html set expandtab
autocmd Filetype ruby setlocal expandtab ts=2 sts=2 sw=2
autocmd Filetype javascript setlocal expandtab ts=2 sts=2 sw=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment