-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc.symlink
455 lines (370 loc) · 15 KB
/
vimrc.symlink
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
" MY NOTES/TIPS/CHEATS
"
" gn - operate on next search match. e.g. `cgn` changes next search match.
" then `.` can be used to repeat the change (or `n`/`N` to navigate
" around w/o repeating the change). w/o operator pending (i.e. `gn`
" alone), just visually select next search match.
" g* - like *, but don't put "\<" and "\>" around the word
" g; - go to [count] older position in change list
" g, - go to [count] newer position in change list
" gp - paste and leave cursor at end
" C-a - increment the first number found on current line after cursor
" @: - repeat command (just like @x runs `x` macro)
" @@ - repeat last macro you ran
" q/ - open search history! Enter to select item
" q: - open command history! Enter to select item
"
" MARKS (move to with quote or backtick: '{mark} -- linewise
" `{mark} -- characterwise exclusive)
"
" ' - position before latest jump (eg, gg=G'' formats entire file
" and returns cursor to where it started)
" [ / ] - beginning / end of last YANK or PASTE
" < / > - beginning / end of last VISUAL SELECTION
"
" Using vim-fugitive for resolving merge conflicts:
" http://vimcasts.org/episodes/fugitive-vim-resolving-merge-conflicts-with-vimdiff/
" tl;dr:
" :Gdiff -- open 3-way diff
" cursor to the branch you want to choose for your working copy, then :dp
" (effectively `:diffput <working-copy-buffer> | diffup[date]`)
" ]c -- cursor to next conflict
" what if you don't want to just take one or the other? i guess just edit
" the working copy manually and then `:diffup`
" when you're done, cursor to working copy and `:Gwrite` -- writes the
" current file to the index (e.g. like `git add`)
" Install vim-plug if not found
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
call plug#begin('~/.vim/plugged')
Plug 'ctrlpvim/ctrlp.vim'
Plug 'preservim/nerdtree'
Plug 'tomtom/tcomment_vim' " (un)commenting with gc{motion} (but mapped to <Leader>c{motion} instead)
Plug 'ntpeters/vim-better-whitespace' " trailing whitespace highlighting, :StripWhitespace to clean file
Plug 'terryma/vim-expand-region' " v/<C-v> to expand/contract selection
Plug 'rking/ag.vim' " better grepping! use :Ag
Plug 'bling/vim-airline' " cool status line
Plug 'vim-syntastic/syntastic' " syntax checking
Plug 'tpope/vim-eunuch' " provides :SudoW[rite] (and some other stuff)
Plug 'tpope/vim-fugitive' " provides :Gblame and friends
Plug 'yssl/QFEnter' " open quickfix file in previously focused window
Plug 'tpope/vim-endwise' " auto-insert `end` in ruby and other langs
Plug 'tpope/vim-surround' " smart edits for things that 'surround' like parens and HTML tags
Plug 'tpope/vim-repeat' " allow `.` repeating of vim-surround commands
Plug 'neoclide/coc.nvim', {'branch': 'release'} " autocompletion/full-on language server support
" Languages
Plug 'vim-ruby/vim-ruby'
Plug 'kana/vim-textobj-user' " dependency of vim-textobj-rubyblock
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'pangloss/vim-javascript'
Plug 'elzr/vim-json'
Plug 'leafgarland/typescript-vim'
Plug 'nono/vim-handlebars'
Plug 'kchmck/vim-coffee-script'
Plug 'mxw/vim-jsx'
Plug 'fatih/vim-go'
Plug 'elixir-lang/vim-elixir'
Plug 'hashivim/vim-terraform'
Plug 'google/vim-jsonnet'
Plug 'pantharshit00/vim-prisma'
Plug 'altercation/vim-colors-solarized'
Plug 'vim-airline/vim-airline-themes'
call plug#end()
" NOTE: to uninstall a plugin, remove it above, restart vim, and do `:PlugClean`
" Space Leader!
let mapleader = "\<Space>"
let maplocalleader = "\<Space>"
" CoC config -----------------------------
" adding an extension to this list will ensure it gets installed. removing
" one does not uninstall it. to do that, remove it, then `:CocUninstall <name>`.
" (and you can tab-complete those names)
" docs: https://github.com/neoclide/coc.nvim/wiki/Using-coc-extensions
let g:coc_global_extensions = [ 'coc-prettier', 'coc-json', 'coc-tsserver', 'coc-eslint', 'coc-prisma' ]
" autocompletion w/ TAB / Shift-TAB
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" 'Return' to insert selected suggestion and apply auto-import if available
" (in a way that doesn't conflict with vim-endwise).
" based off suggestion at: https://github.com/tpope/vim-endwise/issues/125
" except when popup menu is open and nothing is selected, just insert a
" newline (instead of selecting first option)
inoremap <silent> <CR> <C-r>=<SID>coc_confirm()<CR>
function! s:coc_confirm() abort
let selected = complete_info()['selected']
if pumvisible() && selected != -1
return "\<C-y>"
else
return "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
endif
endfunction
" apply 'code actions' (like fixing missing references by importing libs) to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" ... to the current line
nmap <leader>al <Plug>(coc-codeaction-line)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
" nmap <silent> gy <Plug>(coc-type-definition)
" don't like overriding `gi` cuz i use that builtin (jump to last insertion point)
" nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" End CoC config -------------------------
" fzf installed via homebrew, loaded here:
set rtp+=/usr/local/opt/fzf
" hack to get it working with MacVim. works, but slow and annoying.
let g:fzf_launcher = "in_a_new_term_function %s"
" ## Display
" don't break words in middle
set linebreak
" show incomplete paragraphs even when they don't fit on screen (avoid @'s)
set display+=lastline
" always show ruler
set ruler
" turn on syntax hilighting
syntax on
" show line numbers
set number
" allow buffers to be open in the background
set hidden
" keep 5 lines of context on the screen while scrolling, instead of scrolling when cursor is at very bottom
set scrolloff=5
" ...except for in the quickfix window (this is a hassle :/ )
" get rid of scrolloff option for certain buffers like the quickfix and preview windows
autocmd BufEnter *
\ if (&ft=='qf' || &previewwindow || bufname('%') ==# "__Tag_List__") && !exists('s:scrolloff_sav') |
\ let s:scrolloff_sav=&scrolloff |
\ set scrolloff=0 |
\ endif
" File type will not be set on the first BufEnter
autocmd Filetype qf
\ if !exists('s:scrolloff_sav') |
\ let s:scrolloff_sav=&scrolloff |
\ set scrolloff=0 |
\ endif
autocmd BufLeave *
\ if (&ft=='qf' || &previewwindow || bufname('%') ==# "__Tag_List__") && exists('s:scrolloff_sav') |
\ let &scrolloff=s:scrolloff_sav |
\ unlet s:scrolloff_sav |
\ endif
" always show status line (so we see our sweet vim-airline even with only a single split open)
set laststatus=2
" show filename in terminal titlebar
set title
set titlestring=vim\ -\ %f
" Hide scrollbars in gui vims
set guioptions-=L
set guioptions-=R
set guioptions-=l
set guioptions-=r
" ## Theme
set background=dark
let g:airline_theme='base16'
if !has("gui_running")
let g:solarized_termtrans=1
let g:solarized_termcolors=256
endif
colorscheme solarized
" ## Indentation and Tabs
" two spaces pleases
set ts=2
set shiftwidth=2
" and no tab characters!
set expandtab
" round to nearest 2, don't just move 2
set shiftround
" `smartindent` is an obsolete option for C-like syntax. It has been replaced with `cindent`,
" and setting `cindent` also overrides `smartindent`. Vim has indentation
" support for many languages out-of-the-box, and setting `smartindent`
" (or `cindent`, for that matter) in your .vimrc might interfere with this. Use `filetype indent on` and be happy.
set noautoindent
set nosmartindent
filetype plugin indent on
" ## Code Folding
" turn off folding by default
set nofoldenable
" fold by indentation level
set foldmethod=indent
" start out with folds for all but really deep nesting expanded
set foldlevel=9
" ## Spell Checking
" turn it on by default for certain files
" files with extension .es.txt automatically spellchecked in Spanish
au BufNewFile,BufRead *.en.txt set spell
au BufNewFile,BufRead *.es.txt set spelllang=es_es
" ## Backup / Swap file storage
" pull everything together in one place; don't write swap files in cwd
" the trailing `//` causes swap file names to be built from their full path
set backupdir=~/.vim/.swapfiles//
set directory=~/.vim/.swapfiles//
" ## Nitpicks
" eliminate delay after <Esc> from Visual mode (i don't _think_ there are any side effects...?)
set ttimeoutlen=0
" ## Keybindings
nnoremap <Leader>w :w<CR>
nnoremap <Leader>q :q<CR>
" make Y work like D, C, etc.
nnoremap Y y$
" make up, down, j, k keys work intuitively for long paragraphs
nmap <up> gk
nmap <down> gj
nmap j gj
nmap k gk
vmap <up> gk
vmap <down> gj
vmap j gj
vmap k gk
" not in insert mode -- <C-o> can't keep up with my fast key repeat :(
" imap <up> <C-o>gk
" imap <down> <C-o>gj
" CTRL-U in insert mode deletes the current line (does not scroll up a page,
" as it does in normal mode). `CTRL-G u` first will break undo sequence and
" make that line deletion a separate change that can be undone on its own.
inoremap <C-U> <C-G>u<C-U>
" complete in command mode with tab
cnoremap <Tab> <C-L><C-D>
" all the `NERDTreeMirror` stuff makes it so every tab uses the same tree.
nnoremap <silent> <Leader>n :NERDTreeToggle \| NERDTreeMirror<CR>
nnoremap <Leader>N :NERDTreeMirror \| NERDTreeFocus \| wincmd p \| NERDTreeFind<CR>
" [b and ]b for prev/next buffer
nnoremap <silent> [b :bp<CR>
nnoremap <silent> ]b :bn<CR>
" :BD to destroy the buffer but keep the split open (w/ previous buffer in it)
command BD bp\|bd \#
" after indenting in visual mode, retain selection
vnoremap > >gv
vnoremap < <gv
" when pasting in visual mode, don't overwrite the default register
vnoremap p pgvygv<Esc>
" in visual mode, * searches for the selected text
vnoremap * "zy/<C-r>z<CR>
" vim-expand-region maps to v/<C-v>
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" ## Searching
" Highligh found search results, can be turned off with `:noh`
set hlsearch
" This will have searches ignore case unless I use a capital letter
set ignorecase
set smartcase
" Start searching right away instead of waiting for `<CR>`
set incsearch
" fix backspace in insert mode
set backspace=indent,eol,start
"map <silent> <LocalLeader>nh :nohls<CR>
"map <silent> <LocalLeader>rt :!ctags -R --exclude=".git\|.svn\|log\|tmp\|db\|pkg" --extra=+f<CR>
" EASIER SPLIT NAVIGATIONS
" We can use different key mappings for easy navigation between splits to save
" a keystroke. So instead of ctrl-w then j, it’s just ctrl-j:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" MORE NATURAL SPLIT OPENING
" Open new split panes to right and bottom, which feels more natural than
" Vim’s default:
set splitbelow
set splitright
" CtrlP mappings
nnoremap <Leader>o :CtrlP<CR>
nnoremap <Leader>b :CtrlPBuffer<CR>
nnoremap <Leader>m :CtrlPMRUFiles<CR>
nnoremap <Leader>O :CtrlPMixed<CR>
" Copy & paste to system clipboard with <Space>y and <Space>p
nnoremap <Leader>y "+y
nnoremap <Leader>Y "+y$
nnoremap <Leader>d "+d
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
vnoremap <Leader>y "+y
vnoremap <Leader>d "+d
vnoremap <Leader>p "+p
vnoremap <Leader>P "+P
" share links with coworkers
fun! GH(start,end)
" construct github URL
" assume main branch is named 'main' or 'master'
let l:mainBranch = system('git branch -lr | grep -q origin/main && echo main || echo master')
let l:url = 'https://github.com/LumioHX/'
let l:url .= system('basename `git rev-parse --show-toplevel` | tr -d "\n"')
let l:url .= '/blob/' . system('git log -1 --pretty=format:\%h ' . l:mainBranch) . '/' . @%
" if in visual-line mode, add line number(s)
if visualmode() == "V"
let l:url .= '#L' . a:start
if a:start != a:end
let l:url .= '-L' . a:end
endif
endif
echo 'Opening '.l:url
" have to assign the return val, even if we're not using it
let l:jerb = job_start(['open', l:url])
" stick it in the system clipboard, too
let @+ = l:url
endfunction
" i used to call this Blit for Gitblit, so let's see which of these two ends up sticking
command -range GH call GH(<line1>, <line2>)
command -range Blit call GH(<line1>, <line2>)
" enter reruns last test...
"nmap <CR> :wa<CR> :VimuxRunLastCommand<CR>
" ...but does normal thing in quickfix window
"autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
" grep for word/WORD under cursor with leader-g/G
" nnoremap <Leader>g :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" nnoremap <Leader>G :grep! "\b<C-R><C-A>\b"<CR>:cw<CR>
nnoremap <Leader>g :Ag! -wQ "<cword>"<CR>
nnoremap <Leader>G :Ag! -wQ "<cWORD>"<CR>
vnoremap <Leader>g "zy:Ag! -Q "<C-R>z"<CR>
" <F3> to switch between mouse modes
fun! s:ToggleMouse()
if &mouse == ""
set mouse=a
set number
echo "Mouse is for Vim (" . &mouse . ")"
else
set mouse=""
set nonumber " we always go to terminal for copying, so save ourselves a step
echo "Mouse is for terminal"
endif
endfunction
map <F3> :call <SID>ToggleMouse()<CR>
imap <F3> <C-O><F3>
" also set it to vim mode by default
set mouse=a
" TODO: get used to using system clipboard copy/paste instead of mouse
" stuff... also, maybe a mapping for paste-without-formatting, rather than
" doing pastetoggle all the time
" toggle paste, and always report its status
map <F4> :set paste!<CR>:set paste?<CR>
set pastetoggle=<F4>
set history=500 " keep 500 lines of command line history
set formatoptions+=j " Delete comment character when joining commented lines
" ddorman's custom :Ag -- paulh uses a package. might check it out...
" command! -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
" unhighlight search hits
nmap <silent> \n :nohlsearch<CR>
" next/previous buffer
nmap <C-n> :bnext<CR>
nmap <C-p> :bprev<CR>
" This gets used by plugins like ctrlp, ag, and nerdtree
" TODO: maybe i should be using wildignore for this stuff?
let g:ignore_dirs='node_modules'
" little experiment. if the pwd when you open vim has a .vim-ignore-dirs in
" it, then add that to our global ignore_dirs
if filereadable('.vim-ignore-dirs')
let g:ignore_dirs.=' '.join(readfile('.vim-ignore-dirs'), ' ')
endif
" when switching buffers/splits, check to see if the buffer has been
" modified by another process. like what gvim does when it receives
" focus. 'silent!' ignores errors so that windows for which checktime
" doesn't work -- e.g. the Command Line (q:) -- don't complain
autocmd BufWinEnter,WinEnter * silent! checktime
" After whitespace, insert the directory of the current file
" e.g. typing `:echo <C-P>` will expand into something like ':echo /Users/mziwisky'
cnoremap <expr> <C-P> getcmdline()[getcmdpos()-2] ==# ' ' ? expand('%:p:h') : "\<C-P>"