-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
290 lines (237 loc) · 7.25 KB
/
init.vim
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
"" {{{{ Intro }}}}
" TOC:
" Plugins
""" feature extension
""" syntax
""" misc
""" fzf
" Core Vim
""" general
""" whitespace
""" folding
""" searching
""" statusline
""" tabline
" Colorscheme (256 neodark)
" Netrw
" Linter Settings
" Keymappings
" Replace grep with ripgrep
" Last call (path+=**, cd to project)
" Homebrew packages (not necessarily deps for Vim):
""" ripgrep
""" task
""" ctags
""" ruby
""" fzf
" Fonts
""" Adobe Source Code Pro
""" Fira Mono
" Potential TODOs:
" use prettier to format javascript with gq[motion]
" [npm install -g prettier]
" autocmd FileType javascript set formatprg=prettier\ --stdin
"" {{{{ Vim-Plug }}}}
"location of Vim-Plug is ~\AppData\Local\nvim\autoload (see vim-plug repo)
call plug#begin()
"feature extension
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-entire'
"syntax & linting
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'leafgarland/typescript-vim'
"Plug 'scrooloose/syntastic'
"Plug 'mtscout6/syntastic-local-eslint.vim' " use project eslint
"Plug 'unblevable/quick-scope' " cool but distracting
"misc
Plug 'keitanakamura/neodark.vim'
Plug 'wikitopian/hardmode'
call plug#end()
"my plugin :)
"set rtp+=~/.vim/bundle/vim-rctoggle
"fzf
"set rtp+=/usr/local/opt/fzf " mac/homebrew
"set rtp+=~/.fzf " linux/git
"" {{{{ General Settings }}}}
filetype plugin indent on
syntax enable
set encoding=utf-8
set history=1000
set nocompatible " no compatibility with legacy vi, required for Vundle
set number " show line numbers
set ruler
set scrolloff=1 " keep one line displayed above/below cursor
set sessionoptions-=options " don't keep options in sessions
set showcmd " display incomplete commands
set sidescrolloff=5 " keep 5 cols to the left/right of cursor
set tabpagemax=50
set ttimeout
set ttimeoutlen=100
set viminfo^=! " keep capitalized global variables (for plugins)
set wildignore +=**/node_modules/**
set wildmenu
"set relativenumber
au FocusGained,BufEnter * checktime "like gVim, prompt if file changed
"" {{{{ Whitespace }}}}
set autoindent " use indent from prev line when starting new line
set smarttab " use shiftwidth (value used in >> cmd) when tabbing
set nowrap
set tabstop=2 shiftwidth=2
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in insert mode
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
"" {{{{ Folding }}}}
set foldmethod=indent
set foldcolumn=0
"" {{{{ Searching }}}}
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
"" {{{{ statusline, tabline }}}}
set laststatus=2 " always display statusline
set statusline= " clear out for reload
set statusline=%3.3n " buffer number
set statusline+=\ %F " full file path
set statusline+=\ %h%m%r%w " status flags
set statusline+=\ %#warningmsg# " highlight switch
"set statusline+=\ %{SyntasticStatuslineFlag()}
set statusline+=\ %* " highlight exit
set guitablabel= " clear for reload
set guitablabel=%{GuiTabLabel()}
"" {{{{ colorschemes }}}}
let g:neodark#use_256color = 1 " default: 0
colorscheme neodark
set t_Co=256
"" {{{{ netrw }}}}
let g:netrw_banner = 0 " hide banner
"let g:netrw_liststyle = 3 " tree list (causes buffer bug)
"" {{{{ Linting }}}}
" (manual invoke w/:SyntasticCheck)
let g:syntastic_mode_map = { 'mode': 'active',
\ 'active_filetypes': ['javascript'],
\ 'passive_filetypes': [] }
let g:jsx_ext_required = 0
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
" attempted fix for nvm/vim/eslint path issue
" currently resolved with 'local eslint plugin'
" may need to revisit depending on project
" let g:syntastic_javascript_eslint_exec = '~/.nvm/versions/node/v4.2.1/bin/eslint'
let g:syntastic_javascript_checkers = ['eslint']
"" {{{{ Keymappings }}}}
"moving pane manipulation over to space-w, easier to use on 40% keyboards
map <Space> <leader>
noremap <Leader>r <C-r>
noremap <Leader>w <C-w>
noremap <Leader>/ :noh<Cr>
noremap <Leader>h :cd ~/repos/<Cr>
noremap <Leader>p :cd %:p:h<Cr>
" Scripts
noremap gC :call ToggleVimrc()<Cr>
noremap <Leader>= :call Whitespace()<Cr>
noremap <Leader>o :call OpenBrackets()<Cr>
xnoremap <Leader>* :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap <Leader># :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>
" External
" noremap <Leader>F :tabnew +FZF<Cr>
noremap <Leader>G :tabnew +grep\<space>
"noremap gO :!open -a Adobe\ Photoshop\ CS5 <cfile><CR>
"" {{{{ Functions }}}}
function! GuiTabLabel()
let label = ''
let bufnrlist = tabpagebuflist(v:lnum)
" Add '+' if one of the buffers in the tab page is modified
for bufnr in bufnrlist
if getbufvar(bufnr, "&modified")
let label = '+'
break
endif
endfor
" Append the number of windows in the tab page if more than one
let wincount = tabpagewinnr(v:lnum, '$')
if wincount > 1
let label .= wincount
endif
if label != ''
let label .= ' '
endif
" Append the buffer name
return label . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
endfunction
function! Whitespace() " whitespace and endline cleanup function
if !&binary && &filetype != 'diff'
normal mz
normal Hmy
$put _
%s/\s\+$//e
%s#\($\n\s*\)\+\%$##
$put _
normal 'yz<CR>
normal `z
echo "Whitespace cleanup complete."
endif
endfunction
"" for regex breakdown: http://stackoverflow.com/q/7495932/
function! ToggleVimrc() " switch to vimrc depending on context
let s:keep_sb = &switchbuf
set switchbuf=useopen,usetab
let buffernumber = bufnr("~/.vimrc") " -1 if doesn't exist
let currenttab = tabpagenr() " store current buf as fallback
let buffs_arr = []
tabdo let buffs_arr += tabpagebuflist() " collect all buf#s
" return to current page
exec "tabnext ".currenttab
let i = 0
let bnr = 0
for bnum in buffs_arr " iterate thru buf#s, look for match
let i += 1
if bnum == buffernumber
let bnr = i
endif
endfor
if bufnr("%") == buffernumber "if current buf, close
tabclose
elseif bnr > 0 " if match, switchbuf
sb ~/.vimrc
else " else create buff
$tabnew
e $MYVIMRC
endif
let &switchbuf=s:keep_sb
unlet s:keep_sb
endfunction
function! OpenBrackets() abort
" TODO: make the start of insert mode indented
" TODO: have it abort silently
.s/\v(\{|\[)/\1\r/
execute "normal! O"
startinsert
endfunction
" Visual-Star
function! s:VSetSearch(cmdtype)
let temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
let @s = temp
endfunction
"" {{{{ Plugin-specific settings }}}}
" {{{ ripgrep }}}
" use ripgrep (or silver searcher) instead of grep
if executable('rg')
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
set grepformat=%f:%l:%c:%m,%f:%l:%m
elseif executable('ag')
set grepprg=ag\ --vimgrep\ --ignore=\"**.min.js\"
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
" {{{ HardMode }}}
"autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardMode() " call on start
"" {{{{ Last Call }}}}
set path+=** " use ** by default for filepath commands
"cd ~/repos " Change to repos directory