-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
381 lines (365 loc) · 12 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
" vim-plug plugin manager
" put plugins to install (github repos) between begin() and end()
" run :PlugInstall" and restart vim
call plug#begin()
"----workflow----------------------------------------------------------------
" integrate git
Plug 'tpope/vim-fugitive'
" display version control changes
Plug 'mhinz/vim-signify'
" change surrounding delimiters
Plug 'tpope/vim-surround'
" add repeat plugin maps
Plug 'tpope/vim-repeat'
" add pairs of useful maps
Plug 'tpope/vim-unimpaired'
" toggle comments
Plug 'tpope/vim-commentary'
" fix 'path' option
Plug 'tpope/vim-apathy'
" fuzzy find files
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
" prose
Plug 'junegunn/goyo.vim'
" lint
Plug 'dense-analysis/ale'
"----languages---------------------------------------------------------------
" c++ completion
Plug 'xavierd/clang_complete'
" clojure highlighting/repl/completion
Plug 'tpope/vim-fireplace'
" python completion
Plug 'davidhalter/jedi-vim'
"----color themes------------------------------------------------------------
Plug 'fcpg/vim-farout'
Plug 'jnurmine/Zenburn/'
Plug 'morhetz/gruvbox'
Plug 'whatyouhide/vim-gotham'
call plug#end()
"----------------------------------------------------------------------------
" configure options ---------------------------------------------------------
"----------------------------------------------------------------------------
" turn off intro message
set shortmess+=I
" turn off automatic backup
set nobackup
" turn off hidden swap files
set noswapfile
" set this for color to work correctly
set background=dark
" prefer 256 colors
set t_Co=256
set termguicolors
" when (vertically) splitting, open new window to the right
set splitright
" show existing tab with N spaces width
set tabstop=4
" when backspacing, delete N spaces width
set softtabstop=4
" when indenting with '<' or '>', use N spaces width
set shiftwidth=4
" insert spaces instead of tabs
set expandtab
" make tab key insert shiftwidth amount of spaces
set smarttab
" make backspace not insane
set backspace=indent,eol,start
" make join commands insert one space, not two, after '.' '?' or '!'
set nojoinspaces
" when formatting, set text width to N
set textwidth=78
" show sign column
set signcolumn=yes
" show commands
set showcmd
" allow buffers to be hidden
set hidden
" turn off line wrapping
set nowrap
" turn on hybrid mode line numbers
set number " turn on line numbers
set relativenumber " turn on relative line numbers
" highlight cursor's line
set cursorline
" display invisible characters
set list
" use these characters to display invisible characters
" set listchars=tab:>\ ,trail:.,precedes:<,extends:>
set listchars=tab:→\ ,trail:•,precedes:⟨,extends:⟩
" enable mouse
set mouse=a
" turn off folding for all files by default
set nofoldenable
" turn on case insensitivity unless caps are present
set ignorecase
set smartcase
" move cursor to matched searches
set incsearch
" turn off completion scanning current/included files
set complete-=i
" turn on syntax completion
set omnifunc=syntaxcomplete#Complete
" make omni-completion pop-up menu match longest and don't select an option initially
set completeopt=longest,menuone
" enhance command completion
set wildmode=full
set wildignorecase
set wildmenu
" set mapping delay
set timeoutlen=420
" set keycode delay (fixes perceptible latency moving from insert mode to normal mode)
set ttimeoutlen=1
" turn off interpreting leading zero numbers as octal
set nrformats-=octal
" turn on statusline
set laststatus=2
" stop redundant mode printing
set noshowmode
" for use in statusline messages, prettify current mode
let g:currentmode={'n':'NORMAL', 'v':'VISUAL','V':'V-LINE','t':'TERMINAL',"\<C-V>":'V-BLOCK','i':'INSERT','R':'REPLACE','Rv':'V-REPLACE','c':'COMMAND'}
function! GetMode()
return get(g:currentmode, mode(), ' ')
endfunction
" configure status line
set statusline=
" current mode
set statusline+=\ %-{GetMode()}\
" file name
set statusline+=%f
" is modified?
set statusline+=%m
" switching to right section
set statusline+=%=
" file type
set statusline+=\ %y
" file encoding
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
" file line ending
set statusline+=\[%{&fileformat}]
" current line number
set statusline+=\ ln:%l/%{line('$')}
" current col number
set statusline+=\ cn:%c
" percentage scrolled through
set statusline+=\ %p%%
"----------------------------------------------------------------------------
" configure plugins ---------------------------------------------------------
"----------------------------------------------------------------------------
" turn on syntax highlighting
syntax on
" turn on filetype detection, plugin, and indentation
filetype plugin indent on
"--netrw
" disable the banner
let g:netrw_banner=0
" view file listing as a tree
let g:netrw_liststyle=3
"--markdown
augroup filetype_markdown
" clear previous autocommands in this autocommand group
autocmd!
" when text is inserted or deleted, automatically format it
autocmd FileType markdown setlocal formatoptions+=a
" when formatting, preserve list indentation (autoindent option must be on)
autocmd FileType markdown setlocal formatoptions+=n
autocmd FileType markdown setlocal autoindent
" make whitespace continue paragraph
" https://stackoverflow.com/a/21610187
autocmd FileType markdown setlocal formatoptions+=w
augroup END
"--c++
augroup filetype_cpp
" clear previous autocommands in this autocommand group
autocmd!
let g:clang_library_path='/usr/lib/llvm-14/lib/libclang.so.1'
" make ale lint with modern C++20 warnings
let g:ale_cpp_cc_options='-std=c++20 -Wall -Wextra -Wpedantic'
" avoid needing to press shift for scope operator
autocmd FileType cpp inoremap ;; ::
" set c/c++ comment style to '//'
autocmd FileType c,cpp setlocal commentstring=//\ %s
augroup END
"--python
augroup filetype_python
" clear previous autocommands in this autocommand group
autocmd!
" turn off automatic dot completion
let g:jedi#popup_on_dot = 0
" turn off jedi keybindings
let g:jedi#rename_command = ""
let g:jedi#goto_command = "gd"
let g:jedi#goto_assignments_command = ""
let g:jedi#goto_stubs_command = ""
" let g:jedi#usages_command = ""
augroup END
"--fzf
" place preview window thusly
let g:fzf_preview_window = ['up:50%', 'ctrl-/']
"--terminal
augroup terminal_buffer
autocmd!
" turn off line numbers in terminal buffers
autocmd TerminalOpen * setlocal nonumber norelativenumber
" set empty lines below end of buffer to <space>
autocmd TerminalOpen * setlocal fillchars+=eob:\
augroup END
"----------------------------------------------------------------------------
" configure mappings --------------------------------------------------------
"----------------------------------------------------------------------------
" smart tab completion lovingly stolen from here:
" http://vim.wikia.com/wiki/Smart_mapping_for_tab_completion
function! Smart_TabComplete()
" get the word before cursor
let current_line = getline('.')
let until_cursor = strpart(current_line, -1, col('.'))
let substr = matchstr(until_cursor, "[^ \t]*$")
" nothing to match on empty string
if (strlen(substr)==0)
return "\<tab>"
endif
let has_period = match(substr, '\.') != -1
let has_forward_slash = match(substr, '\/') != -1
let has_double_colon = match(substr, '::') != -1
if (!has_period && !has_forward_slash && !has_double_colon)
" existing text matching (syntax omnicompletion)
return "\<c-x>\<c-p>"
elseif (has_forward_slash)
" file matching
return "\<c-x>\<c-f>"
else
" plugin matching
return "\<c-x>\<c-o>"
endif
endfunction
" turn on smart tab completion in insert mode
inoremap <tab> <c-r>=Smart_TabComplete()<cr>
" make pop-up menu more friendly
" found here:
" http://vim.wikia.com/wiki/Improve_completion_popup_menu
" http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
" NB. we can't map <esc> in insert mode for some reason (it turns the arrow keys into letters)
inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<cr>"
inoremap <expr> <down> pumvisible() ? "\<c-n>" : "\<down>"
inoremap <expr> <up> pumvisible() ? "\<c-p>" : "\<up>"
inoremap <expr> <pagedown> pumvisible() ? "\<pagedown>\<c-p>\<c-n>" : "\<pagedown>"
inoremap <expr> <pageup> pumvisible() ? "\<pageup>\<c-p>\<c-n>" : "\<pageup>"
" execute commands
nnoremap <leader><leader> <esc>:
" open vimrc (in new tab)
nnoremap <leader>v :tabnew $MYVIMRC<cr>
" open buffer (in window)
nnoremap <leader>e :e<space>
" open buffer (in new tab)
nnoremap <leader>t :tabnew<space>
" open terminal (in bottom right window)
nnoremap <leader>r :botright terminal<cr>
" open terminal (in new tab)
nnoremap <leader>rr :tab terminal<cr>
" save buffer
nnoremap <leader>w :w<cr>
" switch to the 'alternate file'
nnoremap <tab> <c-^>
" close buffer
nnoremap <leader>x :bd<cr>
" close window or tab
nnoremap <leader>q :q<cr>
" close everything
nnoremap <leader>qq :qa!<cr>
" help
nnoremap <leader>h :h<space>
" reload vimrc
nnoremap <f5> :source $MYVIMRC<cr>
" redo
nnoremap U <c-r>
" copy to end of line similar to C and D operators
nnoremap Y y$
" mark position (remap existing mark line)
nnoremap ' `
" format paragraph
nnoremap Q gqip
vnoremap Q gq
" indent but keep visual highlighting
vnoremap > >gv
vnoremap < <gv
" enter normal mode from terminal mode
tnoremap <esc><esc> <c-\><c-n>
" change tabs focus from terminal mode similar to normal mode
tnoremap <c-pagedown> <c-w>gt<cr>
tnoremap <c-pageup> <c-w>gT<cr>
" change tab focus
nnoremap [t gT
nnoremap ]t gt
" change window focus
nnoremap <silent> <s-up> <c-w>k
nnoremap <silent> <s-down> <c-w>j
nnoremap <silent> <s-right> <c-w>l
nnoremap <silent> <s-left> <c-w>h
inoremap <silent> <s-up> <esc><c-w>ki
inoremap <silent> <s-down> <esc><c-w>ji
inoremap <silent> <s-right> <esc><c-w>li
inoremap <silent> <s-left> <esc><c-w>hi
tnoremap <silent> <s-up> <c-w>k
tnoremap <silent> <s-down> <c-w>j
tnoremap <silent> <s-right> <c-w>l
tnoremap <silent> <s-left> <c-w>h
" change window dimensions
nnoremap <silent> <c-s-up> <c-w>+
nnoremap <silent> <c-s-down> <c-w>-
nnoremap <silent> <c-s-right> <c-w>>
nnoremap <silent> <c-s-left> <c-w><
inoremap <silent> <c-s-up> <esc><c-w>+
inoremap <silent> <c-s-down> <esc><c-w>-
inoremap <silent> <c-s-right> <esc><c-w>>
inoremap <silent> <c-s-left> <esc><c-w><
tnoremap <silent> <c-s-up> <c-w>+
tnoremap <silent> <c-s-down> <c-w>-
tnoremap <silent> <c-s-right> <c-w>>
tnoremap <silent> <c-s-left> <c-w><
" reorder tabs
nnoremap <c-s-pageup> :tabmove -1<cr>
nnoremap <c-s-pagedown> :tabmove +1<cr>
inoremap <c-s-pageup> <esc>:tabmove -1<cr>
inoremap <c-s-pagedown> <esc>:tabmove +1<cr>
tnoremap <c-s-pageup> <c-w>:tabmove -1<cr>
tnoremap <c-s-pagedown> <c-w>:tabmove +1<cr>
" toggle spellchecking
function! ToggleSpell()
set spell!
if &spell
echo 'spellcheck on'
nnoremap <buffer> s 1z=
else
echo 'spellcheck off'
nnoremap <buffer> s s
endif
endfunction
nnoremap <leader>s :call ToggleSpell()<cr>
" fugitive: git blame
nnoremap gb :Git blame<cr>
" fzf: fuzzy find file
nnoremap <leader>p :Files!<cr>
" fzf: fuzzy find buffers
nnoremap <leader>b :Buffers!<cr>
" fzf: grep
nnoremap <leader>g :Rg!<space>
" fzf: grep <cword>
nnoremap gh :Rg!<space><c-r><c-w><cr>
" goyo
let g:goyo_width="88"
let g:goyo_height="75%"
nnoremap <leader>y :Goyo<cr>
" ale: cycle warnings
nnoremap ]a :ALENext<cr>
nnoremap [a :ALEPrevious<cr>
" ale: show warning
nnoremap <leader>a :ALEDetail<cr>
"----------------------------------------------------------------------------
" configure colorscheme -----------------------------------------------------
"----------------------------------------------------------------------------
" select colorscheme and fail silently otherwise
" silent! color farout
" silent! color gotham
" silent! color gruvbox
let g:zenburn_high_Contrast=1 " <--- configure zenburn
silent! color zenburn