-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
328 lines (273 loc) · 11.1 KB
/
.vimrc
File metadata and controls
328 lines (273 loc) · 11.1 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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
scriptencoding utf-8
set encoding=utf-8
" Basic
let mapleader=" " " The <leader> key
set autoread " Reload files that have not been modified
set backspace=2 " Makes backspace behave like you'd expect
set colorcolumn=80 " Highlight 80 character limit
set hidden " Allow buffers to be backgrounded without being saved
set number relativenumber " Show the liner numbes in realtive mode
" set cursorline " Highlight the current line
set ruler " Show the line number and column in the status bar
set scrolloff=999 " Keep the cursor int the center of the screen
set noshowmatch " Don't highlight matching braces
set showmode " Show the current mode on the open buffer
set splitbelow " Splits show up below by default
set splitright " Splits go to the right by default
set title " Set the title for gvim
set visualbell " Use a visual bell to notify us
set nowrap " If the line is too long don't split it on the new line
" Customize session options. Namely, I don't want to save hidden and
" unloaded buffers or empty windows.
set sessionoptions="curdir,folds,help,options,tabpages,winsize"
let g:loaded_matchparen = 1
syntax on " Enable filetype detection by syntax
" Backup settings
set nobackup
set nowritebackup
set noswapfile
set undofile
let &undodir = expand("$HOME") . "/.vim/undodir"
" Search settings
set hlsearch " Highlight results
set ignorecase " Ignore casing of searches
set incsearch " Start showing results as you type
set smartcase " Be smart about case sensitivity when searching
" Tab settings
set expandtab " Expand tabs to the proper type and size
set tabstop=4 " Tabs width in spaces
set softtabstop=4 " Soft tab width in spaces
set shiftwidth=4 " Amount of spaces when shifting
" Tab completion settings
set wildmode=list:longest " Wildcard matches show a list, matching the longest first
set wildignore+=.git,.hg,.svn " Ignore version control repos
set wildignore+=*.6 " Ignore Go compiled files
set wildignore+=*.pyc " Ignore Python compiled files
set wildignore+=*.rbc " Ignore Rubinius compiled files
set wildignore+=*.swp " Ignore vim backups
" Make navigation up and down a lot more pleasent
map j gj
map k gk
" Make splits
nnoremap <leader>s :split<CR>
nnoremap <leader>v :vsplit<CR>
" Make navigating around splits easier
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Shortcut to yanking to the system clipboard
nnoremap <leader>y "+y
vnoremap <leader>y "+y
nnoremap <leader>Y "+Y
vnoremap <leader>Y "+Y
" Shortcut for pasting from without changing the vim buffer
nnoremap <leader>p "_dP
vnoremap <leader>p "_dP
" Shortcut for deleting from without changing the vim buffer
vnoremap <leader>d "_d
" Go back to the file tree
nnoremap <leader>pv :Ex<CR>
" Replace currrent word occurrences
nnoremap <leader>r :%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>
" Get rid of search highlights
noremap <silent><leader>/ :nohlsearch<cr>
" Command to write as root if we dont' have permission
cmap w!! %!sudo tee > /dev/null %
" Buffer management
nnoremap <leader>d :bd<cr>
" Clear whitespace at the end of lines automatically
" autocmd BufWritePre * :%s/\s\+$//e
" Don't fold anything.
autocmd BufWinEnter * set foldlevel=999999
" Plugins
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
Plug 'zaki/zazen'
Plug 'itchyny/lightline.vim'
Plug 'airblade/vim-gitgutter'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'mbbill/undotree'
" Plug 'github/copilot.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()
set termguicolors
set background=dark
colorscheme zazen
" lightline.vim
set laststatus=2
let g:lightline = {
\ 'colorscheme': 'one',
\ }
" ctrlp
let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden --ignore .git --ignore node_modules --ignore dist --ignore target --ignore vendor --ignore tmp --ignore .terraform -g ""'
let g:ctrlp_working_path_mode = 'ra'
nnoremap <leader>ff :CtrlP<CR>
nnoremap <leader>fr :CtrlPMRU<CR>
" fzf
let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.3, 'relative': v:true, 'yoffset': 1.0 } }
let g:fzf_vim_relative_paths = 1
nnoremap <leader>fp :RG<CR>
" vim-gitgutter
let g:gitgutter_sign_added = '+'
let g:gitgutter_sign_modified = '~'
let g:gitgutter_sign_removed = '-'
" undotree
nmap <leader>h :UndotreeToggle<CR>
" vim-lsp
let g:lsp_diagnostics_virtual_text_enabled = 1
let g:lsp_diagnostics_virtual_text_align = 'after'
let g:lsp_settings = {
\ 'gopls': {
\ 'cmd': ['gopls'],
\ 'allowlist': ['go'],
\ 'workspace_config': {
\ 'gopls': {
\ 'staticcheck': v:true,
\ 'analyses': {'unusedparams': v:true},
\ }
\ }
\ },
\ 'typescript-language-server': {
\ 'cmd': ['typescript-language-server', '--stdio'],
\ 'allowlist': ['typescript', 'typescriptreact', 'javascript', 'javascriptreact'],
\ },
\}
highlight LspDiagnosticsVirtualTextError guifg=Red ctermfg=Red
highlight LspDiagnosticsVirtualTextWarning guifg=Yellow ctermfg=Yellow
highlight LspDiagnosticsVirtualTextInformation guifg=Blue ctermfg=Blue
highlight LspDiagnosticsVirtualTextHint guifg=Green ctermfg=Green
nmap <leader>[[ :LspPreviousError<CR>
nmap <leader>]] :LspNextError<CR>
augroup LspCloseReferenceWindow
autocmd!
autocmd FileType qf nnoremap <buffer> <CR> <CR>:cclose<CR>
augroup END
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> 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> rn <plug>(lsp-rename)
nmap <buffer> ca <plug>(lsp-code-action)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
nnoremap <buffer> <expr><c-b> lsp#scroll(-4)
let g:lsp_format_sync_timeout = 1000
augroup lsp_format
autocmd! BufWritePre *.rs,*.go,*.ts,*.tsx,*.js,*.jsx call execute('LspDocumentFormatSync')
augroup END
" refer to doc to add more commands
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" terraform
function! OpenURL(url)
if a:url != ''
let l:command = '!sudo -u ipetrov xdg-open ' . shellescape(a:url) . ' > /dev/null 2>&1 &'
execute l:command
endif
endfunction
function! ConvertProviderToFull(provider_short) abort
let providers = {
\ 'hcp': 'hashicorp/hcp/latest',
\ 'aws': 'hashicorp/aws/latest',
\ 'awscc': 'hashicorp/awscc/latest',
\ 'vault': 'hashicorp/vault/latest',
\ 'cloudflare': 'cloudflare/cloudflare/latest',
\ 'github': 'integrations/github/latest',
\ 'gitlab': 'gitlabhq/gitlab/latest',
\ 'grafana': 'grafana/grafana/latest',
\ 'artifactory': 'jfrog/artifactory/latest',
\ 'platform': 'jfrog/platform/latest',
\ 'project': 'jfrog/project/latest',
\ 'kubernetes': 'hashicorp/kubernetes/latest',
\ 'helm': 'hashicorp/helm/latest',
\ }
return get(providers, a:provider_short, '')
endfunction
function! TerraformDocBrowser()
let l:line = getline('.')
let l:block_pattern = '^\s*\(resource\|data\)\s\+"\([^"]\+\)"\s\+"\([^"]\+\)"'
let l:field_pattern = '^\s*\w\+\s*='
let l:field_block_pattern = '^\s*\(\w\+\)\s*{'
if l:line =~ l:block_pattern
let l:block = matchstr(l:line, '^\s*\(resource\|data\)')
if l:block == 'resource'
let l:block_type = 'resources'
elseif l:block == 'data'
let l:block_type = 'data-sources'
endif
let l:resource_name = substitute(matchstr(l:line, l:block_pattern), '^\s*\(resource\|data\)\s\+"\([^"]\+\)"\s\+"\([^"]\+\)"', '\2', '')
let l:provider_short = matchstr(l:resource_name, '^[^_]\+')
let l:provider = ConvertProviderToFull(l:provider_short)
let l:target = matchstr(l:resource_name, '_\zs.*')
let l:url = 'https://registry.terraform.io/providers/' . l:provider . '/docs/' . l:block_type . '/' . l:target
call OpenURL(l:url)
elseif l:line =~ l:field_pattern || l:line =~ l:field_block_pattern
if l:line =~ l:field_pattern
let l:field = matchstr(l:line, '^\s*\zs\w\+\ze\s*=')
else
let l:field = matchstr(l:line, '^\s*\zs\w\+\ze\s*{')
endif
let l:block_line_num = search(l:block_pattern, 'bnW')
let l:field_block_line_num = search(l:field_block_pattern, 'bnW')
if l:block_line_num > 0
let l:block_line = getline(l:block_line_num)
let l:block = matchstr(l:block_line, '^\s*\(resource\|data\)')
if l:block == 'resource'
let l:block_type = 'resources'
elseif l:block == 'data'
let l:block_type = 'data-sources'
endif
let l:resource_name = substitute(matchstr(l:block_line, l:block_pattern), '^\s*\(resource\|data\)\s\+"\([^"]\+\)"\s\+"\([^"]\+\)"', '\2', '')
let l:provider_short = matchstr(l:resource_name, '^[^_]\+')
let l:provider = ConvertProviderToFull(l:provider_short)
let l:target = matchstr(l:resource_name, '_\zs.*')
if l:line =~ l:field_pattern
let l:url = 'https://registry.terraform.io/providers/' . l:provider . '/docs/' . l:block_type . '/' . l:target . '\#'. l:field . '-1'
elseif l:line =~ l:field_block_pattern
let l:url = 'https://registry.terraform.io/providers/' . l:provider . '/docs/' . l:block_type . '/' . l:target . '\#'. l:field
endif
call OpenURL(l:url)
endif
endif
endfunction
augroup terraform_mappings
autocmd!
autocmd FileType terraform nnoremap <leader>dc :call TerraformDocBrowser()<CR><CR>
augroup END
" vim-go (LSP features delegated to vim-lsp; vim-go used for non-LSP tooling only)
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
let g:go_def_mapping_enabled = 0
let g:go_code_completion_enabled = 0
let g:go_diagnostics_enabled = 0
let g:go_fmt_autosave = 0
let g:go_fmt_command = "goimports"
let g:go_play_browser_command = 'sudo -u ipetrov xdg-open %URL% &'
augroup go_mappings
autocmd!
autocmd FileType go nmap <leader>err :GoIfErr<CR>
autocmd FileType go nmap <leader>dc :GoDocBrowser<CR>
augroup END