-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
283 lines (243 loc) · 8.03 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
277
278
279
280
281
282
283
" .vimrc
" File encodings
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
" Some defaults
set nocp
set visualbell
set wildmenu
set number
set relativenumber
set cursorline
set showmatch
set backspace=2
set mouse=a
set ttymouse=sgr " make it work properly in tmux
set linebreak
" Pathogen
call pathogen#infect()
call pathogen#helptags()
" Indentation options
set tabstop=4
set shiftwidth=4
set expandtab
set smarttab
set autoindent
set textwidth=90
" Search options
set hlsearch
set incsearch
set ignorecase
set smartcase
" Ensure search results appear in the middle of the screen
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
" Columns
set colorcolumn=90
"execute "set colorcolumn=" . join(range(121,800), ',')
" Formatting
set formatoptions=c,q,r,t,b,n
set list listchars=tab:→\ ,trail:·,eol:$
" Status line
set ruler
set laststatus=2
set cmdheight=2
set shortmess=a
"set statusline=%F%m%r%h%w\ %{fugitive#statusline()}\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
let g:airline#extensions#tabline#enabled = 0
let g:airline_theme='powerlineish'
let g:airline_powerline_fonts = 1
" Remember cursor location on close
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Location of vim files
set viminfo='10,\"100,:20,%,n~/.vim/viminfo
set backupdir=~/.vim/backup/
set directory=~/.vim/swp/
" Colors & Syntax highlighting
filetype plugin indent on
syntax on
let g:solarized_termtrans=1
let g:solarized_termcolors=256
let g:solarized_diffmode="high"
let g:solarized_visibility="low"
set background=light
colorscheme solarized
hi ColorColumn ctermbg=231
hi LineNr ctermbg=231
hi CursorLine ctermbg=lightyellow
" Jedi-vim options
let g:jedi#force_py_version = 3
let g:jedi#use_splits_not_buffers = "left"
" <leader>k opens Vexplorer
let g:netrw_liststyle=3
let g:netrw_winsize = 75
map <leader>k :Vexplore<cr>
map <leader>t :terminal<cr>
" F8 after search collapses everything unmatched
set foldexpr=getline(v:lnum)!~@/
map <F8> :set foldmethod=expr<CR><Bar>zM
" Small function to calculate sum in a column
command! -range=% -nargs=1 SumColumn <line1>,<line2>!awk -F '|' '{print; sum+=$('<args>' + 1)} END {print "Total: "sum}'
" XML folding
augroup XML
autocmd!
autocmd FileType xml let g:xml_syntax_folding=1
autocmd FileType xml setlocal foldmethod=syntax
autocmd FileType xml :syntax on
autocmd FileType xml :%foldopen!
augroup END
" vim-terraform configuration
let g:terraform_align=1
let g:terraform_fold_sections=1
let g:terraform_fmt_on_save=1
autocmd FileType terraform setlocal foldmarker={,}
" syntastic configuration
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_aggregate_errors = 1
let g:syntastic_enable_signs=1
let g:syntastic_error_symbol = '✗✗'
let g:syntastic_style_error_symbol = '✠✠'
let g:syntastic_warning_symbol = '∆∆'
let g:syntastic_style_warning_symbol = '≈≈'
" vim-airline / syntastic integration
let g:airline#extensions#syntastic#enabled = 1
let g:airline#extensions#syntastic#error_symbol = '✗✗:'
let g:airline#extensions#syntastic#stl_format_err = '%E{[%e(#%fe)]}'
let g:airline#extensions#syntastic#warning_symbol = '∆∆:'
let g:airline#extensions#syntastic#stl_format_warn = '%W{[%w(#%fw)]}'
let g:syntastic_html_tidy_ignore_errors = ['trimming empty']
let g:syntastic_python_checkers = ['flake8']
" golang
let g:syntastic_go_checkers = ['errcheck', 'go']
let g:go_fmt_experimental = 1
let g:go_rename_command = 'gopls'
let g:go_auto_type_info = 0
let g:go_debug_windows = {'vars': 'rightbelow 60vnew', 'stack': 'rightbelow 10new'}
autocmd FileType go setlocal foldmethod=syntax
autocmd FileType go set completeopt=longest,menuone
" jsonnet / tanka
let g:syntastic_jsonnet_checkers = ['jsonnet']
" Only check formatting because of Tanka import paths
let g:syntastic_jsonnet_jsonnet_exec = 'jsonnetfmt'
autocmd FileType jsonnet setlocal foldmethod=syntax
autocmd FileType jsonnet setlocal foldlevelstart=1
" Template (bash)
augroup templates
autocmd BufNewFile *.sh 0r ~/.vim/templates/skel.bash
augroup END
" Spellcheck
autocmd FileType markdown setlocal spell spelllang=en_us
autocmd FileType gitcommit setlocal spell spelllang=en_us
" Checklist
nnoremap <leader>cc :ChecklistToggleCheckbox<cr>
nnoremap <leader>ce :ChecklistEnableCheckbox<cr>
nnoremap <leader>cd :ChecklistDisableCheckbox<cr>
vnoremap <leader>cc :ChecklistToggleCheckbox<cr>
vnoremap <leader>ce :ChecklistEnableCheckbox<cr>
vnoremap <leader>cd :ChecklistDisableCheckbox<cr>
au BufNewFile,BufRead *.chklst setf checklist
let g:checklist_filetypes = ['markdown', 'checklist']
let g:vim_markdown_folding_disabled = 1
let g:fugitive_git_command = 'git'
function! Openfile()
call feedkeys("\<CR>\<C-W>w")
endfunction
" Opens URL in browser
nnoremap gx :!xdg-open <cWORD> &<CR><CR>
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=500
echo 'Highlight current word: ON'
return 1
endif
endfunction
" Fold at a specific level
" Source: https://stackoverflow.com/a/25644411
function! FoldToTheLevel(TheLevel)
"set mark "f" at current position
execute "normal! mf"
"close all the folder recursively
execute "normal! ggVGzC"
"open all the folder which have smaller level
let h=0
while h<a:TheLevel
execute "normal! ggVGzo"
let h+=1
endwhile
"open all the folder which have larger level
folddoclosed execute "normal! VzOzc"
"jump back and show in the middle
execute "normal! `fzz"
endfunction
command! -nargs=1 F call FoldToTheLevel(<f-args>)
" JSONNET
function! JsonnetEval()
" check if the file is a tanka file or not
let output = system("tk tool jpath " . shellescape(expand('%')))
if v:shell_error
let output = system("jsonnet " . shellescape(expand('%')))
else
let output = system("tk eval " . shellescape(expand('%')))
endif
vnew
setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile ft=jsonnet
put! = output
endfunction
map <leader>j :call JsonnetEval()<cr>
let g:lsp_log_verbose = 1
let g:lsp_log_file = expand('~/vim-lsp.log')
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gp <plug>(lsp-peek-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
inoremap <buffer> <expr><c-f> lsp#scroll(+4)
inoremap <buffer> <expr><c-d> lsp#scroll(-4)
let g:go_gopls_enabled = 0
let g:jsonnet_fmt_on_save = 0
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.rs,*.go,*.jsonnet,*.libsonnet call execute('LspDocumentFormatSync')
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() : "\<cr>"