-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
437 lines (353 loc) · 11.8 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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
set nocompatible
filetype off
" set runtime path to include vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" plugins managed by vundle
call vundle#begin()
Plugin 'gmarik/Vundle.vim' " (required for vundle)
Plugin 'tpope/vim-surround'
Plugin 'jiangmiao/auto-pairs'
Plugin 'godlygeek/tabular'
Plugin 'bling/vim-airline'
Plugin 'scrooloose/nerdtree'
Plugin 'sjl/gundo.vim'
" Plugin 'jremmen/vim-ripgrep'
" Plugin 'yssl/QFEnter'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
" Linting
"Plugin 'scrooloose/syntastic'
Plugin 'w0rp/ale'
" Colors
Plugin 'mhartington/oceanic-next'
"Git
Plugin 'tpope/vim-fugitive'
" orgmode
Plugin 'jceb/vim-orgmode'
Plugin 'vim-scripts/utl.vim'
Plugin 'majutsushi/tagbar'
Plugin 'mattn/calendar-vim'
Plugin 'tpope/vim-speeddating'
Plugin 'tpope/vim-repeat'
" Haskell
Plugin 'neovimhaskell/haskell-vim'
" Plugin 'enomsg/vim-haskellConcealPlus'
Plugin 'eagletmt/ghcmod-vim'
Plugin 'eagletmt/neco-ghc'
" Elm
Plugin 'ElmCast/elm-vim'
" Elixir
Plugin 'elixir-editors/vim-elixir'
Plugin 'tomtom/tlib_vim'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'scrooloose/nerdcommenter'
Plugin 'lukerandall/haskellmode-vim'
Plugin 'Twinside/vim-hoogle'
Plugin 'bitc/vim-hdevtools'
"Plugin 'travitch/hasksyn'
Plugin 'ervandew/supertab'
"Tidal
Plugin 'munshkr/vim-tidal'
"Python
Plugin 'petobens/poet-v'
Plugin 'vim-scripts/indentpython.vim'
"Javascript
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'othree/html5.vim'
"Typescript
Plugin 'leafgarland/typescript-vim'
"C++
Plugin 'rhysd/vim-clang-format'
"Kotlin
Plugin 'udalov/kotlin-vim'
"Rust
Plugin 'rust-lang/rust.vim'
"Completion
Plugin 'Valloric/YouCompleteMe'
Plugin 'Shougo/vimproc'
"Plugin 'kien/ctrlp.vim'
Plugin 'tikhomirov/vim-glsl'
Plugin 'emnh/taglist.vim'
Plugin 'tmhedberg/matchit'
call vundle#end()
filetype plugin indent on
" --- General Settings ---
set backspace=indent,eol,start
set encoding=utf-8
set ruler
set number
set showcmd
set incsearch
set hlsearch
set nospell
set ignorecase
set smartcase
set hidden " Allow modified buffers to be hidden without unloading
set nowrap " Don't wrap long lines
set showmode " Display the current mode
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set splitright " Puts new vsplit windows to the right of the current
set splitbelow " Puts new split windows to the bottom of the current
set autoindent " Keep the indentation when creating a new line
set smartindent " Syntax-based indenting
set showmatch " Briefly flash matching parens while typing
set wildmenu " Show list of matches when using :b or :find
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
set list
"set columns=150
"set lines=50
set path+=** " Allow :find to recursively search subpaths
set diffopt+=vertical " Always open diffs in a vertical split
set complete-=i " Disable ^N searching included files (slow)
" GUI Settings
set guifont=Source\ Code\ Pro:h15
set guioptions=cgm
" Strip trailing whitespace
autocmd FileType asm,c,cpp,java,elixir,go,php,haskell,javascript,puppet,python,ruby,rust,sql,twig,xml,yml,perl autocmd BufWritePre <buffer> | call StripTrailingWhitespace()
function! StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/\s\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" enable mouse interaction through terminal
set mouse=a
" enable syntax menu functions
" source /usr/share/vim/vim74/synmenu.vim
" --- Mappings ---
let mapleader = ','
let maplocalleader = '\'
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
" Hide search highlighting with ,/
nmap <silent> <leader>/ :nohlsearch<CR>
" Map H and L to move between buffers. Conflicts with ability to move to
" bottom/top of screen, so first remap those to gh, gl.
nnoremap gh <S-H>
nnoremap gl <S-L>
nnoremap <S-H> :bprev<CR>
nnoremap <S-L> :bnext<CR>
" Visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
" Allow using the repeat operator with a visual selection (!)
" http://stackoverflow.com/a/8064607/127816
vnoremap . :normal .<CR>
" Remap * to highlight the word under the cursor without moving to next result
nnoremap * mxHmz`x*`zzt`x
" Nerd tree file browser
noremap <C-O> :NERDTreeToggle<CR>
noremap <C-H> :NERDTree
" move between splits with alt
nnoremap ∆ <C-W><C-J>
nnoremap ˚ <C-W><C-K>
nnoremap ¬ <C-W><C-L>
nnoremap ˙ <C-W><C-H>
" iterate error list with alt
nnoremap ∫ :cprev <CR>
nnoremap µ :cnext <CR>
" return cursor to first window (often NERDTree)
nnoremap <leader><C-O> 1<C-W>w
" folding
nnoremap <space> za
" call make with leader+m
nnoremap <leader>m :make<CR>
" jumplist forward/backward
nnoremap <C-K> <C-O>
nnoremap <C-J> <C-I>
" write without losing position on line
nnoremap <silent> <leader>w :silent call WriteSaveCursor()<CR>
function! WriteSaveCursor()
let save_cursor = getpos(".")
write
call setpos('.', save_cursor)
endfunction
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
" --- Colour Scheme ---
colorscheme liquidcarbon
set background=dark
syntax on
" --- Status Bar ---
set laststatus=2
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
set statusline+=%{fugitive#statusline()} " Git Hotness
set statusline+=\ [%{&ff}/%Y] " Filetype
set statusline+=\ [%{getcwd()}] " Current dir
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
" --- No tabs!! ---
set shiftwidth=2 " Use indents of 2 spaces
set tabstop=2 " An indentation every 2 columns
set softtabstop=2 " Let backspace delete indent
set smarttab " make tab insert indents instead of tabs at the beginning of a line
set expandtab " always uses spaces instead of tab characters
" --- Syntax Highlighting ---
let asmsyntax='armasm'
let filetype_inc='armasm'
" Exit insert mode from the home row
"inoremap kj <ESC>
" shorten the timeout for sequential shortcuts in insert mode
set timeoutlen=500
" Don't screw up folds when inserting text that might affect them, until
" leaving insert mode. Foldmethod is local to the window. Protect against
" screwing up folding when switching between windows.
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
" --- Setting up directories ---
set backup " Backups are nice ...
if has('persistent_undo')
set undofile " So is persistent undo ...
set undolevels=1000 " Maximum number of changes that can be undone
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
endif
" Initialize directories
function! InitializeDirectories()
let parent = $HOME
let prefix = 'vim'
let dir_list = {
\ 'backup': 'backupdir',
\ 'views': 'viewdir',
\ 'swap': 'directory' }
if has('persistent_undo')
let dir_list['undo'] = 'undodir'
endif
let common_dir = parent . '/.' . prefix
for [dirname, settingname] in items(dir_list)
let directory = common_dir . dirname . '/'
if exists("*mkdir")
if !isdirectory(directory)
call mkdir(directory)
endif
endif
if !isdirectory(directory)
echo "Warning: Unable to create backup directory: " . directory
echo "Try: mkdir -p " . directory
else
let directory = substitute(directory, " ", "\\\\ ", "g")
exec "set " . settingname . "=" . directory
endif
endfor
endfunction
call InitializeDirectories()
" --- Plugin Settings ---
" Ale
let g:ale_linters = {
\ 'cpp': [],
\ 'javascript': ['eslint'],
\ 'python': ['mypy', 'pylint'],
\ 'rust': ['cargo', 'analyzer'],
\ 'scss': ['stylelint'],
\ 'typescript': ['eslint', 'tsserver'],
\ 'typescriptreact': ['eslint', 'tsserver']
\}
let g:ale_fixers = {
\ 'cpp': [],
\ 'go': ['gofmt', 'goimports'],
\ 'javascript': ['prettier'],
\ 'python': ['isort', 'black'],
\ 'rust': ['rustfmt'],
\ 'scss': ['prettier'],
\ 'typescript': ['prettier'],
\ 'typescriptreact': ['prettier']
\}
let g:ale_fix_on_save = 1
let g:ale_rust_rustfmt_options = '--edition 2021'
" Syntastic
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 0
" let g:syntastic_check_on_open = 0
" let g:syntastic_check_on_wq = 0
" map <silent> <Leader>e :Errors<CR>
" map <Leader>s :SyntasticToggleMode<CR>
" Tabularize align columns around a character
map <leader>t :Tab<CR>
" Airline
"Fancy arrow symbols, requires a patched font
"let g:airline_powerline_fonts = 0
" Show PASTE if in paste mode
"let g:airline_detect_paste = 1
" Show airline for tabs too
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_tabs = 0
" ghc-mod
let g:haddock_docdir = "~/Library/Haskell/share/doc/x86_64-osx-ghc-7.10.2/"
let g:haddock_browser = "/Applications/Google Chrome.app"
" enable filetype detection, plus loading of filetype plugins
filetype plugin on
" speed-dating
autocmd VimEnter * SpeedDatingFormat! %v
autocmd VimEnter * SpeedDatingFormat! %^v
" gundo
nnoremap <F5> :GundoToggle<CR>
let g:gundo_return_on_revert = 0
" fugitive
nnoremap <leader>gw :Gwrite<CR>
nnoremap <leader>gr :Gread<CR>
nnoremap <leader>gc :Git commit<CR>
nnoremap <leader>gs :Git status<CR>
nnoremap <leader>gp :Git pull<CR>
nnoremap <leader>gP :Git push<CR>
nmap <leader>sp :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" CtrlP
let g:ctrlp_custom_ignore = 'node_modules'
" YouCompleteMe
let g:ycm_autoclose_preview_window_after_insertion = 1
nnoremap <leader>] :YcmCompleter GoToType<CR>
nnoremap <C-]> :YcmCompleter GoToType<CR>
nnoremap <leader>[ :YcmCompleter GoToReferences<CR>
nnoremap <leader>; :YcmCompleter GoTo<CR>
nnoremap <leader>d :YcmCompleter GetDoc<CR>
nnoremap <leader>f :YcmCompleter FixIt<CR>
nmap <D-CR> <plug>(YCMHover)
nnoremap <leader>c :pclose<CR>
nnoremap <leader>r :YcmCompleter RefactorRename
" Navigation in jumplist
nnoremap <leader>o <C-O>
nnoremap <leader>i <C-I>
" vim-ripgrep
nnoremap <leader>a :RG<CR>
nnoremap <leader>* yiw:RG <C-r>"<CR>
vnoremap <leader>a y:RG <C-r>"<CR>
"nnoremap <leader>a :Rg ''<left>
"vnoremap <leader>a y:Rg -i '<C-r>"'<CR>
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
" Poetry
let g:poetv_auto_activate = 1
let g:poetv_executables = ['poetry']
" FZF
let $FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
nnoremap <C-P> :Files<CR>
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let $FZF_DEFAULT_OPTS = '--bind ctrl-l:select-all+accept'