-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
334 lines (240 loc) · 7.92 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
set nocompatible " Make Vim more useful.
set modeline " Use modlines?
set modelines=1 " Use modlines?
" Layout / window stuff {{{
set laststatus=2 " Always show the status line.
set ruler " Show the line coordinates and file position in status line.
set showcmd " Show the last command typed in the status line.
set number " Why is this even an option? (show line numbers).
set nowrap " Do not visual word wrap lines.
set hidden " Buffers remain in memory when not attached.
set cursorline " Highlight the line the cursor is on.
set colorcolumn=80 " Put a bar down column 80.
set signcolumn=yes " It is wildly jarring when this toggles otherwise
" }}}
set backspace=indent,eol,start " What should BS do?
set history=1000
set mouse=a
" Indenting and tabs {{{
set autoindent " Preserve indenting when starting new line.
set expandtab " Use spaces, rather than tab char.
set tabstop=4 " How many spaces should be used for tab?
set shiftwidth=4 " Number of spaces for (auto)indent.
set softtabstop=4 " Number of spaces tab counts for.
"}}}
" Searching {{{
set noincsearch " Disable incremental search
set hlsearch " Highlight search matches.
" }}}
" How to display assorted non-printing chars
set listchars=eol:$,tab:▸\ ,trail:~,extends:>,precedes:<
set wildmode=longest:full " Autocomplete longest possible common segment.
set wildmenu " Show an auto-complete list.
set wildignore+=*.pyc " Do not autocomplete pyc files.
set wildignorecase " Ignore case in path completion.
" Autocomplete is basically unusable (for me) when set to scan for included
" files.
set complete=.,w,b,u,t " Default '.,w,b,u,t,i'; The i says included files.
" Backup files {{{
set backup
set backupdir=~/tmp/vim/backup//
set backupskip=/tmp/*,~/tmp/*
set writebackup
" Put undo files in a special safe place.
set undofile
set undodir=~/tmp/vim/undo//
" Put swap files in a special place.
set directory=~/tmp/vim/swap//
"}}}
" Key Bindings {{{
" Fix Y to work like other Caps, such as D.
nnoremap Y y$
" Make shell commands run like they normally would
" NOTE: This really hoses up vim-fugitive.
" set shellcmdflag=-ic
" Remap window nav to ctrl-[h,j,k,l]
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" nnoremap <C-x> <C-w>x
" jj as shortcut for escape
noremap! jj <Esc>
" ;; for find next inline.
nnoremap ;; ;
" ,, for find previous inline.
nnoremap ,, ,
" ; for cmd-mode entry
nnoremap ; :
" Better buffer explorer.
nnoremap <C-t> :buffers<CR>:buffer<space>
"}}}
" Leader Mappings {{{
" remap leader from \
let mapleader = ","
" cancel highlight shortcut
map <leader><cr> :noh<cr>
" Toggle spell mode on/off.
map <leader>p :set spell!<cr>:set spell?<cr>
" toggle current column highlight shortcut.
map <leader>c :set cursorcolumn!<cr>:set cursorcolumn?<cr>
" toggle between relative and absolute line numbers.
map <leader>r :set rnu!<cr>:set rnu?<cr>
" toggle paste mode.
map <leader>e :set paste!<cr>:set paste?<cr>
" toggle gundo on/off.
map <leader>g :GundoToggle<CR>
" Toggle hidden chars.
map <leader>l :set list!<cr>
" Sort
map <leader>s :sort<cr>
"}}}
" insert wd of current file.
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" plug.vim {{{
"
"
call plug#begin('~/.vim/plugged')
Plug 'sjl/gundo.vim'
Plug 'kien/rainbow_parentheses.vim'
Plug 'sheerun/vim-polyglot'
Plug 'airblade/vim-gitgutter'
Plug 'gruvbox-community/gruvbox'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
"}}}
" Enable filetype plugins
filetype plugin indent on
syntax on
set re=0
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
autocmd BufWrite *.py call CocActionAsync('format')
autocmd FileType python nnoremap <silent> <buffer> <leader>T :sfind test_%:t
" Spell check in git commits
autocmd FileType gitcommit setlocal spell
autocmd FileType gitcommit setlocal complete+=kspell
" Spell check in Markdown files
autocmd FileType markdown setlocal spell
autocmd FileType markdown setlocal complete+=kspell
" Fix Silly Plugins {{{
" Tell gundo to prefer python3
let g:gundo_prefer_python3 = 1
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" nnoremap zj :lnext<CR>zz
" nnoremap zk :lprev<CR>zz
" " Remap keys for gotos
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)
" Map keys for doc helpers
nnoremap <silent> K :call CocActionAsync('doHover')<CR>
" Create mappings for function text object, requires document symbols feature
" of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')
"}}}
" Make Colors More Nicer {{{
set background=dark
set t_Co=256
" Hmmmm. This sucks
" let g:gruvbox_guisp_fallback = "bg"
colorscheme gruvbox
" Toggle high-contrast mode on/of
function! ToggleContrast()
if !exists('g:current_contrast')
let g:current_contrast = 0
endif
if g:current_contrast < 0
let g:gruvbox_contrast_dark = 'medium'
let g:current_contrast = 0
echo " medium contrast mode"
elseif g:current_contrast == 0
let g:gruvbox_contrast_dark = 'hard'
let g:current_contrast = 1
echo " hard contrast mode"
else
let g:gruvbox_contrast_dark = 'soft'
let g:current_contrast = -1
echo " soft contrast mode"
endif
colorscheme gruvbox
endfunction
map <leader>h :call ToggleContrast()<cr>
"}}}
function! ScrollToPercent(percent)
let movelines=winheight(0)*a:percent/100
if has("float") && type(movelines) == type(0.0)
let movelines=float2nr(movelines)
endif
let oldso=&so
execute ":set so=" . movelines
execute "normal! zt"
execute ":set so=" . oldso
endfunction
nnoremap za :<C-u>call ScrollToPercent(20)<cr>
function! ZoomMode()
if !exists("t:zoom_mode_enabled")
echo " zoommode"
" If zoom mode is on, make windows a size usable for coding as we jump
" between them.
set winwidth=84
" We have to have a winheight bigger than we want to set winminheight.
" But if we set winheight to be huge before winminheight, the
" winminheight set will fail.
set winheight=15
set winminheight=15
set winheight=999
" Mark ZoomMode as currently on.
let t:zoom_mode_enabled = 1
else
echo "nozoommode"
" If zoom mode is not on, set resize limits much lower.
set winwidth=20
set winheight=15
set winminheight=1
set winheight=1
" Make sure zoom mode marked as off.
unlet t:zoom_mode_enabled
endif
endfunction
silent! call ZoomMode()
" Toggle zoom mode on/off.
map <leader>z :call ZoomMode()<cr>
function! ExecTmuxCommand()
" I can not decide if I like auto-save or not. For now, not.
"execute ":w"
if exists('b:exec_command')
let l:command = b:exec_command
elseif exists('w:exec_command')
let l:command = w:exec_command
else
let l:command = g:exec_command
endif
if exists('b:exec_target')
let l:target = b:exec_target
elseif exists('w:exec_target')
let l:target = w:exec_target
else
let l:target = g:exec_target
endif
call SendTmuxCommands(l:target, l:command)
endfunction
function! SendTmuxCommands(...)
for pair in range(0, a:0 - 2, 2)
let l:target = a:{pair + 1}
let l:command = a:{pair + 2}
exec ":silent !tmux send-keys -t " . l:target . " '" . l:command . "' Enter Enter"
endfor
execute ":redraw!"
endfunction
let g:exec_target = "+1"
let g:exec_command = '\!\!'
nmap <leader>t :call ExecTmuxCommand()<CR>
" vim:foldmethod=marker:foldlevel=0