-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc_go_development
More file actions
190 lines (167 loc) · 6.59 KB
/
vimrc_go_development
File metadata and controls
190 lines (167 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
""" Vundle configuration and packages
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" Multiple Cursors
Plugin 'terryma/vim-multiple-cursors'
" Undo tree
Plugin 'mbbill/undotree'
" Surround.vim (surround text with "([{' etc)
Plugin 'tpope/vim-surround'
" Repeat.vim (some plugins work with '.')
Plugin 'tpope/vim-repeat'
" ctrlp - fuzzy file finder, etc
Plugin 'ctrlpvim/ctrlp.vim'
" fugitive.vim (Git plugin for vim)
Plugin 'tpope/vim-fugitive'
" GitGutter (displays git changes)
Plugin 'airblade/vim-gitgutter'
" Airline
Plugin 'vim-airline/vim-airline'
" Go extentions
Plugin 'fatih/vim-go'
" YouCompleteMe (autocomplete)
Plugin 'ycm-core/YouCompleteMe'
" Syntastic: error highlighting
" Plugin 'vim-syntastic/syntastic'
" For matching parentheses I think?
Plugin 'andymass/vim-matchup'
" Typescript syntax highlighting
" Plugin 'HerringtonDarkholme/yats.vim'
" Plugin for editing latex
Plugin 'lervag/vimtex'
" Plugin for snippets
Plugin 'SirVer/ultisnips'
" Built-in snippets for UltiSnips
Plugin 'honza/vim-snippets'
" Markdown syntax highlighting
Plugin 'gabrielelana/vim-markdown'
call vundle#end()
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
" `filetype plugin on`
""" General options
" colorscheme ron - commented b/c I prefer 'default' these days
set smartindent
set ai
set tabstop=2
set shiftwidth=2
set number
set ruler
set relativenumber
set mmp=10000 " Avoids bug where syntax highlighting large go files can fail
" Replace tabs with spaces -- not always necessary
set expandtab
set incsearch
set nojoinspaces " Only put one space after '.' when joining lines.
syntax on
" Create undodir & configure vim to use it
silent exec "! test -d ${HOME}/.vim/undodir || mkdir -p ${HOME}/.vim/undodir"
set undodir=~/.vim/undodir
" Don't unindent comments in python
" TODO: install pep8 indentation rules for python
" See https://stackoverflow.com/questions/2360249/vim-automatically-removes-indentation-on-python-comments#comment12772473_2360284
au Filetype python inoremap # X<BS>#
" Set indent to 2 spaces in python
au Filetype python setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Add C-k shortcut for vim-matchup, to show which conditional block you're in
" in heavily-nested code
nnoremap <c-k> :<c-u>MatchupWhereAmI?<cr>
""" Autocommands and autogroups
augroup format_on_write
" au is just short form for autocmd. Like :w and :write. :au! clears other
" autocommands in this autogroup, so that :source-ing my vimrc doesn't
" cause autocommands to stack
au!
" Commands executed before writing a buffer to a file.
" Clean up all trailing whitespace
" Note: trailing whitespace is meaningful in markdown
au BufWritePre .bashrc,*.cc,*.h,*.java,*.py,*.sh,*.json,*.proto,*.js silent! %s/[ ]\+$//g
" This is a good place to put autoformatting
" For example: `au FileType markdown AutoFormatBuffer mdformat`
augroup END
augroup set_colorcolumn_on_filetype
au!
" Run `:set filetype?` to see the filetype for the current file
au Filetype java set colorcolumn=101,102 | set textwidth=100
au Filetype cpp,python,go,proto,rust set colorcolumn=81,82 | set textwidth=80
au Filetype sh set colorcolumn=81,82 " Don't set textwidth--bash is harder to wrap
augroup END
augroup set_soft_wrap_on_markdown
au!
au Filetype markdown set wrap linebreak nolist
augroup END
augroup relative_number_in_normal_mode
au!
au InsertEnter * :set number
au InsertLeave * :set relativenumber
augroup END
" This is a function I added specifically to help when working on Pachyderm
" tests. Clients have a context, and often in tests I have to call
" alice.DoSomething(alice.Ctx(), ...). A common mistake I make in tests is:
" alice.DoSomething(bob.Ctx(), ...) (typically a copy/paste error). This
" autocommand catches those types of errors
function! Highlight_silly_ctx_error()
hi Error ctermbg=Red
match Error /\(\<[a-z]\w\+\)\.[A-Z]\w\+(\(\1\)\@!\w\+\.Ctx()/
endfunction
augroup pachyderm_go_autocmds
au!
au BufRead /home/mjs/code/**.go
\ call Highlight_silly_ctx_error()
augroup END
function! Highlight_pc_kc()
hi Error ctermbg=Red
match Error /pc\|kc/
endfunction
augroup catch_abbrevs_bash
au!
au Filetype sh call Highlight_pc_kc()
augroup END
hi ColorColumn ctermbg=Gray ctermfg=Black guibg=gray9
" Fix syntastic coloring that blends in with my highlight
" http://stackoverflow.com/questions/17677441/changing-error-highlight-color-used-by-syntasti
hi SpellBad ctermfg=Black ctermbg=Red
hi SpellCap ctermfg=Black ctermbg=Yellow
" highlight all occurrences of a match (like emacs)
hi Search ctermbg=DarkYellow
" Search terms stay highlighted after search is done, until I move the cursor
set hlsearch
" Type <space> to clear search highlighting
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" Search is case-insensitive, unless it contains uppercase letters
set ignorecase
set smartcase
" Highlight trailing whitespace
match Search /\s\+$/
""" Vim surround options
" (tweaks)
" Typing ESC in insert or visual mode doesn't lose your cursors. You have to go
" to normal mode to drop them
let g:multi_cursor_exit_from_visual_mode=0
let g:multi_cursor_exit_from_insert_mode=0
" Make numbers work when replaying normal mode commands for multiple cursors
" This is the default value (as documented on terryma's github page) plus the
" digits
let g:multi_cursor_normal_maps = {
\ '!':1, '@':1, '=':1, 'q':1, 'r':1, 't':1, 'T':1, 'y':1, '[':1, ']':1,
\ '\':1, 'd':1, 'f':1, 'F':1, 'g':1, '"':1, 'z':1, 'c':1, 'm':1, '<':1,
\ '>':1, '0':1, '1':1, '2':1, '3':1, '4':1, '5':1, '6':1, '7':1, '8':1,
\ '9':1
\ }
""" Go options (place these at the end of the file, after vundle#end())
" let g:go_fmt_command = "goimports"
" let g:syntastic_go_checkers = ['go', 'golint', 'govet -composites=false', 'errcheck']
let g:syntastic_go_checkers = ['golint', 'govet -composites=false', 'errcheck']
let g:syntastic_check_on_wq = 0 " Normally syntastic checks on writes, but don't check on 'wq'
let g:go_list_type = "quickfix"
let g:go_autodetect_gopath = 0 " For some reason, if I don't set this, my GOPATH is modified and imports fail to resolve
let g:go_build_tags = 'unit_test k8s server' " Used by some projects' unit tests (so you don't waste time building tests for prod builds)
let g:go_def_mode = 'gopls'
let g:go_info_mode = 'gopls'
" See :h g:go_debug. This can help debug weird vim-go errors
" let g:go_debug=['shell-commands', 'lsp']