-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
269 lines (225 loc) · 8.48 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
" file setup
:syntax on
:set ignorecase
:set number
:set mouse=
:set hlsearch
:set incsearch
:set encoding=utf-8
:set fileencoding=utf-8
:set fileformat=unix
" disable .netrwhist nonsense
:let g:netrw_dirhistmax = 0
" tab stuff
:set autoindent
:set expandtab
:set smarttab
:set tabstop=2
:set softtabstop=2
:set shiftwidth=2
" navigation (from http://statico.github.com/vim.html)
" go up and down one row, not one line (useful for wrapped lines)
:nmap j gj
:nmap k gk
" tab next/prev with shift h and shift l
nnoremap <S-h> gT
nnoremap <S-l> gt
" jump between last opened buffer with Ctrl+E (:b# and :e# do same thing)
:nmap <C-e> :e#<CR>
" jump between syntastic syntax errors on location-list with :ll
" title setting
"autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
autocmd BufEnter * let &titlestring = "vim(" . expand("%:t") . ")"
" assorted automatic syntax loading. filetype -> syntax
" see https://github.com/vim-syntastic/syntastic/wiki/%28v3.7.0%29---Syntax-Checkers for list of plugins
au BufRead *.md set filetype=markdown
" NOTE: install `gem install mdl` for markdown setup
au BufRead *.scala set filetype=scala
au BufRead *.pp set filetype=puppet
au BufRead *.jade set filetype=jade
au BufRead *.go set filetype=go
au BufRead *.erb set filetype=erb
autocmd BufNewFile,BufRead *.ts setlocal filetype=typescript
" highlight trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
:autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
"let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]"
let &titlestring = "vim(" . expand("%:t") . ")"
if &term == "screen"
set t_ts=k
set t_fs=\
endif
if &term == "screen" || &term == "xterm" || &term == "xterm-color" || &term == "xterm-256color"
set title
endif
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()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Keep Plugin commands between vundle#begin/end.
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-airline/vim-airline'
Plugin 'artanikin/vim-synthwave84'
Plugin 'neoclide/coc.nvim', {'branch': 'release'}
Plugin 'hashivim/vim-terraform'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim', { 'do': { -> fzf#install() } }
Plugin 'skywind3000/asyncrun.vim'
"Plugin 'ShoofLLC/vim-openai' " needs: pip3 install click openai
"Plugin 'codota/tabnine-vim'
" wondering why tabnine suggestion isnt working? run this in vim:
" :CocInstall coc-tabnine
call vundle#end() " required
filetype plugin indent on " requiredPlug 'junegunn/fzf', { 'do': { -> fzf#install() } }
if has('termguicolors')
set termguicolors " 24-bit terminal
else
let g:synthwave_termcolors=256 " 256 color mode
endif
" set colorscheme after termguicolors, or the background gets messed up
:set background=dark
:color synthwave84
nnoremap <silent> <C-t> :GFiles<CR>
nnoremap <silent> <C-p> :Ag<CR>
nnoremap <silent> <C-l> :Lines<CR>
" ctrl-h to lookup help for the current focused word as input
nnoremap <silent> <C-h> :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
let g:fzf_layout = { 'down': '20%' }
" https://github.com/skywind3000/asyncrun.vim#quickfix-window
" https://github-wiki-see.page/m/skywind3000/asyncrun.vim/wiki/Quickfix-Best-Practice
" quickfix window will open when something adds to it
augroup vimrc
" when QF is modified, reopen QF window
autocmd QuickFixCmdPost * call QFOpen()
" automatically open QF when asyncrunstart fires
autocmd User AsyncRunStart call QFOpen()
autocmd User AsyncRunStop call QFCloseIfHappy()
autocmd FileType go call GoOptions()
autocmd FileType terraform noremap <C-k> :AsyncRun terraform plan<cr>
autocmd FileType ruby noremap <C-k> :AsyncRun rake test<cr>
" when in quickfix window (:copen/:cclose) map <esc> to quit the pane
autocmd FileType qf nnoremap <buffer><silent> <esc> :quit<cr>
augroup END
function GoOptions()
noremap <C-k> :AsyncRun make test<cr>
endfunction
function QFOpen()
call asyncrun#quickfix_toggle(8, 1)
endfunction
function QFCloseIfHappy()
" let the window hang out for 6 seconds before autoclosing
" call timer_start(6000, { tid -> execute('call asyncrun#quickfix_toggle(8, 0)')})
endfunction
" run make command when you ctrl-k
"nnoremap <silent> <C-K> :AsyncRun! make<CR>
":call asyncrun#quickfix_toggle(8)
" these are default, but it doesnt hurt to call out improved search with
" snapping to search term
:set hlsearch
:set incsearch
" Ignore cases, but only when the cases are not uniform. That is, make
" searching case-sensitive when there are upper and lower case letters.
:set ignorecase
:set smartcase
" set useful format options. see `:help fo-table` for more.
:set formatoptions=jtcroqln
" https://mandreyel.github.io/posts/fav-vim-settings/
"
fun! s:SetRelativeNumber()
if &number
set relativenumber
endif
endfun
fun! s:UnsetRelativeNumber()
if &number
set norelativenumber
endif
endfun
" automatically turn on relativenumbering when in command mode, and
" norelativenumber when in insert
augroup NumberToggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * call s:SetRelativeNumber()
autocmd BufLeave,FocusLost,InsertEnter * call s:UnsetRelativeNumber()
augroup END
" --- coc trigger ---
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" --- end coc trigger ---
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" reminder to self - use gx to go to a URL under cursor
" none of these work well yet
"nmap gx "zy:!open "http://www.google.com/search?q=<c-r>\""
"nmap gx :!open "http://www.google.com/search?q=<c-r>=substitute(@z,' ','%20','g')<cr>"
"nmap gx :!open <c-r><c-a>
"nmap gx :!open "http://www.google.com/search?q=<c-r>=substitute(@z,' ','%20','g')<cr>"<return>gv
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
set statusline^=%{coc#status()}
" set overlength highlights for 80char lines
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
"match OverLength /\%120v.\+/ " highlight all characters over 100char
match OverLength '\%101v.' " highlight only the 101st character in a column
" terraform specific settings
" https://github.com/hashivim/vim-terraform
let g:terraform_align=1
let g:terraform_fmt_on_save=1
let g:coc_global_extensions = [
\'coc-json',
\'coc-git',
\'coc-html',
\'coc-css',
\'coc-yaml',
\'coc-sh',
\'coc-tsserver',
\'coc-pyright',
\'coc-solargraph']