-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
380 lines (304 loc) · 12.3 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
set nocompatible
" Activate the vim package manager, pathogen
"execute pathogen#infect()
call plug#begin()
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-tags.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'vim-airline/vim-airline-themes'
Plug 'vim-airline/vim-airline'
Plug 'scrooloose/nerdtree'
Plug 'simnalamburt/vim-mundo'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-sleuth'
Plug 'thinca/vim-localrc'
call plug#end()
"""""""""""""""
" Basic Setup "
"""""""""""""""
set encoding=utf-8
set ff=unix
set nowrap
behave xterm
set title " show filename in the window title
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set hlsearch " highlight search terms
set number " show line numbers
set showtabline=1 " only show tab bar if more than one tab
set laststatus=2 " always show the status bar
"set smartcase " if search is lowercase, ignorecase, otherwise case-sensitive
set mouse=a " enable mouse in all modes
if has("mouse_sgr")
set ttymouse=sgr " required for mouse to work correctly on macos
else
set ttymouse=xterm2 " hack for tmux to fix mouse movements in vim through tmux
end
set history=100 " lines of command line history to keep
set undofile " enable persistent undo
set undodir=~/.vimundo
"set backup " keep a backup file
set nohidden " when a tab is closed, remove the buffer
set noautoread " do not automatically reload the file if changed on disk
set sessionoptions=buffers,curdir,tabpages,winsize " things to save when saving the current session
"set switchbuf+=usetab,newtab " Open a file in existing tab if already open, otherwise new tab
set backspace=indent,eol,start whichwrap+=<,>,[,] " backspace and cursor keys wrap to previous/next line
filetype plugin on " enable filetype plugins
filetype indent off " no filetype indent
set noautoindent " no auto indent
set nosmartindent " no smart indentation
autocmd FileType * set nosmartindent formatoptions-=cro " Disable auto indenting and auto comment, even after the filetype plugin re-enables it
let g:asyncomplete_auto_popup = 0 " Don't open the autocomplete until Ctrl-N is pressed
let g:asyncomplete_auto_completeopt = 0 " Set completeopt such that it opens a menu, selects the first option, but doesn't automatically insert
set completeopt=menuone,noinsert
" Cool tab completion stuff
set wildmenu
"set wildmode=list:longest,full
"""""""""""
" Colours "
"""""""""""
function! ApplyCustomColors()
" If the Pmenu background is Magenta, then change it to a more visible color
let output = execute('highlight Pmenu')
if output =~ '.*Magenta.*'
highlight Pmenu ctermbg=darkblue guibg=darkblue
endif
highlight Error guibg=NONE
endfunction
" Switch syntax highlighting on, when the terminal has colors or the gui is running
if &t_Co > 2 || has("gui_running")
syntax on
syntax sync fromstart
let g:allcolors = map(split(globpath(&runtimepath . ",/usr/share/vim-scripts/color_sampler_pack/", 'colors/*.vim'), "\n"), 'fnamemodify(v:val, ":t:r")')
let g:allairline = map(split(globpath(&runtimepath, 'plugged/vim-airline-themes/autoload/airline/themes/*.vim'), "\n"), 'fnamemodify(v:val, ":t:r")')
let g:favcolors = [ 'badwolf', 'darkblue', 'desert', 'elflord', 'evening', 'flattown', 'gentooish', 'gotham', 'greenvision', 'industry', 'jellyx', 'koehler', 'leo', 'lettuce', 'lodestone', 'murphy', 'pablo', 'ron', 'slate', 'Sunburst', 'torte', 'vividchalk', 'mustang', 'anokha', 'anotherdark', 'astroboy', 'asu1dark', 'autumnleaf', 'bigbang', 'blacksea', 'bluegreen', 'breeze', 'brookstream', 'calmar256-dark', 'candy', 'candycode', 'clarity', 'colorer', 'dante', 'darkZ', 'darkblue2', 'darkbone', 'darkburn', 'darkslategray', 'darkspectrum', 'dejavu', 'desert256', 'desertEx', 'dusk', 'dw_blue', 'dw_green', 'dw_orange', 'dw_purple', 'dw_red', 'dw_yellow', 'earendel', 'ekvoli', 'fnaqevan', 'freya', 'fruity', 'fu', 'golden', 'guardian', 'herald', 'inkpot', 'jammy', 'jellybeans', 'kellys', 'liquidcarbon', 'manuscript', 'marklar', 'maroloccio', 'masmed', 'matrix', 'metacosm', 'midnight2', 'molokai', 'moss', 'motus', 'navajo-night', 'neon', 'neverness', 'night', 'night_vision', 'nightshimmer', 'no_quarter', 'northland', 'oceanblack', 'oceandeep', 'railscasts', 'rdark', 'relaxedgreen', 'rootwater', 'sea', 'settlemyer', 'softblue', 'sorcerer', 'synic', 'tabula', 'tango', 'tango2', 'tesla', 'tir_black', 'twilight', 'two2tango', 'vibrantink', 'vimhut', 'wombat', 'wuye', 'xoria256', 'zenburn', 'zendnb', 'zmrok' ]
let g:colors = g:favcolors
let g:colors_last = 0
let g:seed = srand()
function! RandomColor()
let g:colors_last = rand(g:seed) % len(g:colors)
execute 'colorscheme ' . get(g:colors, g:colors_last)
call ApplyCustomColors()
endfunction
command Random call RandomColor()
nmap <C-C><C-R> :Ra<CR>
function! ColorNext()
let g:colors_last = (g:colors_last + 1) % len(g:colors)
execute 'colorscheme ' . get(g:colors, g:colors_last)
call ApplyCustomColors()
endfunction
command NC call ColorNext()
nmap <C-C><C-N> :NC<CR>
function! ColorPrev()
let g:colors_last = (g:colors_last - 1) % len(g:colors)
execute 'colorscheme ' . get(g:colors, g:colors_last)
call ApplyCustomColors()
endfunction
command PC call ColorPrev()
nmap <C-C><C-P> :PC<CR>
function! RandomAirline()
let g:airline_theme = get(g:allairline, rand(g:seed) % len(g:allairline))
endfunction
command RA call RandomAirline()
nmap <C-C><C-S> :RA<CR>
call RandomColor()
"let g:airline_theme = 'badwolf'
call RandomAirline()
nmap <C-C><C-S> :AirlineTheme random<CR>
endif
"""""""""""""
" Functions "
"""""""""""""
function! ToggleLineLength()
" Highlight lines that are too long
hi LineOverflow ctermfg=white ctermbg=red guifg=white guibg=#FF2270
if !exists('w:m1')
let w:m1=matchadd('LineOverflow','\%>120v.\+', -1)
else
call matchdelete(w:m1)
unlet w:m1
endif
endfunction
command TLL call ToggleLineLength()
function! ToggleTrailingSpace()
" Highlight trailing spaces
hi TrailingSpaces ctermfg=white ctermbg=red guifg=white guibg=#FF2270
if !exists('w:m2')
let w:m2=matchadd('TrailingSpaces','\s\+$', -1)
else
call matchdelete(w:m2)
unlet w:m2
endif
endfunction
command TTS call ToggleTrailingSpace()
""""""""""""""""
" Key Bindings "
""""""""""""""""
" Horizontal Scrolling
map <C-ScrollWheelDown> 20zl
map <C-ScrollWheelUp> 20zh
" Right
map <S-Right> 40zl
vmap <S-Right> 40zl
imap <S-Right> <C-O>40zl
" Left
map <S-Left> 40zh
vmap <S-Left> 40zh
imap <S-Left> <C-O>40zh
" Set Copy/Cut/Paste keys depending on if the clipboard is present
if has('clipboard')
" Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
" Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" Paste
map <C-V> "+gP
cmap <C-V> <C-R>+
imap <C-V> <C-R>+
else
" If the X clipboard is not present, then the + register wont exist, so use the z register instead
" Copy
vnoremap <C-C> "zy
vnoremap <C-Insert> "zy
" Cut
vnoremap <C-X> "zx
vnoremap <S-Del> "zx
" Paste
map <C-V> "zgP
cmap <C-V> <C-R>z
imap <C-V> <C-R>z
endif
" Remap Visual Block command (which was CTRL-V)
noremap ; <C-V>
noremap <C-Q> <C-V>
command! Vb normal! <C-V>
" Use CTRL-S for saving
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
" CTRL-Tab is Next window
noremap <C-Tab> <C-W>w
inoremap <C-Tab> <C-O><C-W>w
cnoremap <C-Tab> <C-C><C-W>w
" Maximize Current Window
map <C-W><C-M> <C-W>_
" // in Visual mode will search for selected text
vnoremap // y/\V<C-r>=escape(@",'/\')<CR><CR>
"""""""""""""""""""""""""
" User-Defined Commands "
"""""""""""""""""""""""""
" Use 4 character tabs instead of 8 (\t* + 4 spaces)
command SmartTabs set ts=8 sw=4 sts=4 smarttab
command ST SmartTabs
" Use 4 character tabs instead of 8 but expand all tabs to spaces
command PythonTabs set ts=8 sw=4 sts=4 smarttab expandtab
command PT PythonTabs
" Use 2 character tabs instead of 8 but expand all tabs to spaces
command WebTabs set ts=8 sw=2 sts=2 smarttab expandtab
command WT WebTabs
" Reset to tabs with a tabstop of 8
command ResetTabs set ts=8 sw=8 sts=0 noexpandtab nosmarttab
command RT ResetTabs
" Enable word wrap
command SetWrap set wrap linebreak
command SW SetWrap
" Change to current file's directory
command CH cd %:p:h
command LCH lcd %:p:h
" Enable word wrap
command FixSync syntax sync fromstart
command FS FixSync
""""""""""""""""""""""""
" Filetype Adjustments "
""""""""""""""""""""""""
" For arduino *.ino files, treat as a C++ file
autocmd BufRead,BufNewFile *.ino setfiletype cpp
" For *.py files, set the tabstop to 4 and expand tabs to space
autocmd BufRead,BufNewFile *.py PythonTabs
" For *.js files, set the tabstop to 4 and expand tabs to space
autocmd BufRead,BufNewFile *.js PythonTabs
" For *.pyhtml files, treat as a HTML file
autocmd BufRead,BufNewFile *.pyhtml setlocal syntax=aspperl
" For *.md and *.txt files, enable spell check
autocmd BufRead,BufNewFile *.md setlocal spell
" Fix syntax highlighting
autocmd BufEnter * :syntax sync fromstart
" Disable autocomments
autocmd BufEnter * set formatoptions-=cro
"""""""""""""""""
" Miscellaneous "
"""""""""""""""""
" Sleuth disable auto indent
let g:did_indent_on = 0
" Enable Powerline fonts in airline
"set rtp+=/usr/local/lib/python3.7/dist-packages/powerline/bindings/vim/
let g:airline_powerline_fonts=1
"Setup rust-analyzer
if executable('rust-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'Rust Language Server',
\ 'cmd': {server_info->['rust-analyzer']},
\ 'whitelist': ['rust'],
\ })
"set signcolumn=yes
endif
" Register ccls C++ lanuage server.
if executable('ccls')
au User lsp_setup call lsp#register_server({
\ 'name': 'ccls',
\ 'cmd': {server_info->['ccls']},
\ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'compile_commands.json'))},
\ 'initialization_options': {'cache': {'directory': expand('~/.cache/ccls') }},
\ 'allowlist': ['c', 'cpp', 'objc', 'objcpp', 'cc'],
\ })
endif
" Register ccls haskell lanuage server.
if executable('haskell-language-server-wrapper')
au User lsp_setup call lsp#register_server({
\ 'name': 'haskell-language-server-wrapper',
\ 'cmd': {server_info->['haskell-language-server-wrapper', '--lsp']},
\ 'root_uri':{server_info->lsp#utils#path_to_uri(
\ lsp#utils#find_nearest_parent_file_directory(
\ lsp#utils#get_buffer_path(),
\ ['.cabal', 'stack.yaml', 'cabal.project', 'package.yaml', 'hie.yaml', '.git'],
\ ))},
\ 'whitelist': ['haskell', 'lhaskell'],
\ })
endif
function! s:on_lsp_buffer_enabled() abort
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gD <plug>(lsp-document-diagnostics)
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)
let g:lsp_format_sync_timeout = 1000
let g:lsp_diagnostics_virtual_text_enabled = 0
let g:lsp_diagnostics_virtual_text_prefix = " ‣ "
let g:lsp_diagnostics_virtual_text_align = "right"
let g:lsp_diagnostics_virtual_text_wrap = "truncate"
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
command D LspDocumentDiagnostics
if !empty(glob("~/.vimrc.local"))
source ~/.vimrc.local
endif