-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
276 lines (230 loc) · 6.6 KB
/
vimrc
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
"" Vim appearance plugins
Plugin 'gcmt/taboo.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tomasr/molokai'
"" Editing plugins
Plugin 'bronson/vim-trailing-whitespace'
Plugin 'ConradIrwin/vim-bracketed-paste'
Plugin 'sjl/gundo.vim'
"" Navigation and search plugins
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'mileszs/ack.vim'
"" Coding plugins
Plugin 'tpope/vim-endwise'
Plugin 'scrooloose/nerdcommenter.git'
" Git plugins
Plugin 'airblade/vim-gitgutter'
Plugin 'tpope/vim-fugitive'
" Go plugins
Plugin 'fatih/vim-go'
" YARA
Plugin 's3rvac/vim-syntax-yara'
" Language server
Plugin 'dense-analysis/ale'
call vundle#end()
syntax enable
set encoding=utf-8
set showcmd
set relativenumber "Use relative line numbers for easier motions
set hidden
set wildmenu
set history=200 "Remember last 200 commands
set ttimeout
set ttimeoutlen=100
filetype plugin indent on
set noswapfile
set shell=bash\ -l
"" Whitespace
set nowrap
set tabstop=2 shiftwidth=2
set expandtab
set backspace=indent,eol,start
set nofixeol
"" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
"Global replace in line by default. Turn off by supplying g in substitute command
set gdefault
"" Display
set splitright
set splitbelow
set laststatus=2
set scrolloff=3
set sidescrolloff=5
set textwidth=88
set colorcolumn=93
set lazyredraw
set cursorline
"" Command window
" Truncate all messages to reduce prompting
set shortmess+=T
set cmdheight=2
set visualbell t_vb=
"" Colors
set t_Co=256
silent! colorscheme molokai
" Fix wonky matching parentheses
hi MatchParen ctermfg=233 ctermbg=208 cterm=bold,reverse
"" *** PLUGIN SETTINGS ***
"" ack
let g:ackhighlight = 1
let g:ack_default_options = " -s -H --nocolor --nogroup --column --smart-case --follow --ignore-file=ext:a"
"" ctrlp
let g:ctrlp_cmd = 'CtrlP'
" Allow search by line as well
let g:ctrlp_extensions = ['line']
let g:ctrlp_max_files = 10000
let g:ctrlp_show_hidden = 1
let g:ctrlp_working_path_mode = "ra"
"" gitgutter
let g:gitgutter_map_keys = 0
"" gundo
let g:gundo_prefer_python3 = 1
"" netrw
let g:netrw_liststyle = 2
let g:netrw_banner = 0
let g:netrw_winsize = 15
let g:netrw_browse_split = 2
"" taboo
let g:taboo_tabline = 0
"" vim-airline
let g:airline_powerline_fonts = 0
let g:airline_theme="dark"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#tabline#show_buffers = 0
let g:airline#extensions#ale#enabled = 1
"" Linter
let g:ale_linters = { "python": ["mypy", "ruff"] }
"" Formatter
let g:ale_fixers = { "python": ["ruff_format"] }
let g:ale_sign_column_always = 1
let g:ale_fix_on_save = 1
"" vim-go
let g:go_auto_sameids = 0
let g:go_auto_type_info = 1
let g:go_fmt_command = "goimports"
let g:go_list_type = "quickfix"
" linter isn't always reliable
let g:go_metalinter_autosave = 0
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck', 'deadcode']
" gopls works for module renaming
let g:go_rename_command = "gopls"
let g:go_template_use_pkg = 1
let g:go_test_show_name = 1
"" *** KEYMAPS ***
" Leader is now comma
let mapleader=","
" Toggle line numbers
noremap <Leader>n :set invnumber<CR>
" Disable cursor keys
"noremap <Left> <NOP>
"noremap <Right> <NOP>
"noremap <Up> <NOP>
"noremap <Down> <NOP>
"inoremap <Left> <NOP>
"inoremap <Right> <NOP>
"inoremap <Up> <NOP>
"inoremap <Down> <NOP>
" Navigate quickfix list
noremap <silent> <Leader>; :cp<CR>
noremap <silent> <Leader>' :cn<CR>
noremap <silent> <Leader>l :cclose<CR>
" Move right window to left
nnoremap <Leader>ww <C-w>H<C-w>=
" Hide search highlights
nnoremap <silent> <Space> :noh<CR>
" Temporarily open an shell, type exit to return to vim
nnoremap <Leader>s :sh<CR>
" Close all windows except current
nnoremap <Leader>qw :only<CR>
" Close all tabs except current
nnoremap <Leader>qt :tabonly<CR>
" Edit ~/.vimrc in new tab
nnoremap <silent> <Leader>vimrc :tabe $MYVIMRC<CR>
" Switch to previously edited buffer
nnoremap <Leader>b :b#<CR>
" (TODO) Use PCRE for regex
nnoremap / /\v
" Change working directory to directory of current file
nnoremap <Leader>lcd :lcd %:h<CR>:pw<CR>
" Change working directory back to original working directory
nnoremap <Leader>cd :cd<CR>:pw<CR>
" Open netrw as visual split
nmap <Leader>x :Vexplore<CR>
" Disable macro recording
noremap q <NOP>
" Navigate windows
noremap <silent> [h <C-w>h
noremap <silent> ]j <C-w>j
noremap <silent> ]k <C-w>k
noremap <silent> ]l <C-w>l
"" *** PROGRAMMING KEYMAPS AND CONFIGS ***
""Bash
au FileType sh setlocal nowrap formatoptions-=t
"" Dockerfile
au FileType dockerfile setlocal nowrap formatoptions-=t
""Go
" Show go test results (clear only works on Linux)
au FileType go nnoremap <Leader>tt :!clear && go test ./...<CR>
au FileType go setlocal autoread
"" YARA
au BufNewFile,BufRead *.yar,*.yara setlocal filetype=yara
"
"" isort
" Install isort with pipx install isort
au FileType python nnoremap <Leader>i :!isort % <CR><CR>
au FileType python setlocal autoread
"" *** PLUGIN KEYMAPS ***
"" ack
nnoremap <C-f> :Ack!<space>
noremap <Leader>fw :Ack! "<cword>"<CR>
noremap <Leader>todo :Ack! todo<CR>
"" CtrlP
nnoremap <Leader>pg :let g:ctrlp_working_path_mode = 'ra'<CR>:CtrlP<CR>
nnoremap <Leader>pd :let g:ctrlp_working_path_mode = 'a'<CR>:CtrlP<CR>
"" gundo
nnoremap <F5> :GundoToggle<CR>
"" nerdcommenter
" Toggle line comment
map <Leader>/ <Plug>NERDCommenterToggle
" (TODO) Other less-used NERDCommenter functionality
map <Leader>// <Plug>NERDCommenterYank
"" vim-go
augroup auto_go
au!
au BufWritePost *.go :exe "FixWhitespace" | :GoBuild!
au BufWritePost *_test.go :exe "GoTestCompile!"
augroup end
" gd for go-def
au FileType go nmap <Leader>r <Plug>(go-run)
au FileType go nmap gf <Plug>(go-referrers)
au FileType go nmap <Leader>t :wa<CR><Plug>(go-test)
au FileType go nmap <Leader>tf :wa<CR><Plug>(go-test)
au FileType go nmap <Leader>av <Plug>(go-alternate-vertical)
au FileType go nmap <Leader>a <Plug>(go-alternate-edit)
"" (TODO) already mapped as gd
au FileType go nmap gdv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dd <Plug>(go-decls)
au FileType go nmap <Leader>da <Plug>(go-decls-dir)
au FileType go nmap gr :GoRename<Space>
au FileType go nmap <Leader>gl <Plug>(go-metalinter)
"" ale
au FileType python nmap <silent> <Leader>j <Plug>(ale_previous_wrap)
au FileType python nmap <silent> <Leader>k <Plug>(ale_next_wrap)
"" *** RUNTIME! ***
" Press % to navigate beween brace/bracket pairs
runtime! macros/matchit.vim
"" *** AUTOMAGIC ***
augroup reload_vimrc " {
au!
au BufWritePost $MYVIMRC source $MYVIMRC | :AirlineRefresh
augroup END " }