-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
312 lines (224 loc) · 7.47 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
" ex: set foldmethod=marker
set nocompatible
" Behaviour {{{
" She's a beaut!
color solarized
" True programmers use dark backgrounds
set background=dark
" Show line numbers
set number
" Show common line limits
set colorcolumn=80,120
" Highlight the line that the cursor is on
set cursorline
" Mouse scrolling in a terminal
set mouse=a
map <ScrollWheelUp> <C-Y>
map <ScrollWheelDown> <C-E>
" Underline spelling mistakes
set spell
" Ignore backup files as these settings tend to become
" nuisances over time, rather than help.
set nobackup
set noswapfile
" Share the system clipboard with vim
set clipboard=unnamed
" Do not wrap lines
set nowrap
" Properly show invisibles
set list listchars=tab:·\ ,trail:•
" Wrap at 80 lines. It's still important.
set textwidth=80
" Indent with two spaces. These settings will most likely
" be autodetected by the autoindent plugin anyway.
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
" Search globally by default
set gdefault
" Case-insensitive searches by default until you type
" a captial letter, then switch to case-sensitive
set ignorecase
set smartcase
" Auto-reload files changed on disk
set autoread
" Show context above and below the cursor
set scrolloff=5
" Wrap lines when moving around the file
set whichwrap+=<,>,h,l
" Show a navigable menu for tab completion
set wildmenu
" Allow per-project settings
set exrc
" Context-dependent cursor in the terminal
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" Auto-save after a brief period of time
autocmd CursorHold,CursorHoldI * silent! wa
" Automatically balance splits
autocmd VimResized,BufNew !nerdtree wincmd =
" Most PHP is 4 spaces these days
au FileType php setlocal softtabstop=4 tabstop=4 shiftwidth=4
" Treat ES6 as straight up Javascript, yo.
au BufNewFile,BufRead *.es6 set filetype=javascript
" Don't wrap on HTML. That shit gets so long it's not funny.
au FileType html,htmldjango,htmljinja setlocal textwidth=0 wrapmargin=0
" Don't replace past buffer
function! RestoreRegister()
let @" = s:restore_reg
if &clipboard == "unnamed"
let @* = s:restore_reg
endif
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
vmap <silent> <expr> p <sid>Repl()
" }}}
" Mappings {{{
" Even better than the comma
let mapleader = " "
" Because ESC is just too far away
inoremap jj <ESC>
" And Shift-; is just too darn difficult
noremap ; :
" Fast [w]rites and [q]uits
nnoremap <Leader>w :w!<CR>
nnoremap <Leader>wq :wq!<CR>
nnoremap <Leader>q :q!<CR>
" Fast [r]emoval of files
nnoremap <Leader>rm :w!<CR>:call delete(expand('%'))<CR>:bdelete<CR>
" [O]pen the containing folder of a file in Finder
nnoremap <Leader>fo :silent !open -Rg %<CR>:redraw!<CR>
" Toggle search highlighting
nnoremap <Leader><Space> :set hlsearch!<CR><esc>
" Quickly create new splits. These have a nice, simple
" way of opening up that's similar to sublime.
nnoremap <Leader>v :botright vnew<CR><C-W>l
nnoremap <Leader>s :belowright new<CR><C-W>j
" Afford quickly moving around splits
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Quickly change indent
vnoremap <C-l> >gv
vnoremap <C-h> <gv
" Quickly toggle code comments
map \\ <plug>NERDCommenterToggle
" [G]it integration
nnoremap <Leader>gs :Gstatus<CR>
nnoremap <Leader>gc :Gcommit<CR>
nnoremap <Leader>gb :Gblame<CR>
nnoremap <Leader>gp :Git push<CR>
nnoremap <Leader>ga :Git commit --amend<CR>
" Git [d]iff in the gutter. There's some sort of bug with the background
" colour that's fixed with running it this way. Adding the first
" statement doesn't fix anything if I do it inline...
nnoremap <Leader>gd :hi clear SignColumn<CR> :GitGutterToggle<CR>
" Fuzzy filename searching with ctrl-[p]
let g:ctrlp_map = '<Leader>p'
" Grep with [a]g, aka the silver searcher
nnoremap <Leader>a :Ag ''<Left>
" Quickly [m]aximize a split
nnoremap <Leader>m :ZoomWin<CR>
" Show an [o]utline of the file with tagbar
nnoremap <Leader>o :TagbarToggle<CR>
" Start Easy Align's interactive mode
vnoremap <silent> <Space> :EasyAlign<CR>
" Disable these mappings which I tend to just
" fat-finger and end up getting in my way
map K k
" But [K] is very useful, so keep it around
nnoremap <Leader>k K
" }}}
" Configuration {{{
"
" Disable airline's pretty separators because
" I'm too lazy to use the patched font.
let g:airline_left_sep = ''
let g:airline_right_sep = ''
" Add spaces after comments and remove them when removing comments
let g:NERDSpaceDelims = 1
let g:NERDRemoveExtraSpaces = 1
" Only show git gutter when requested,
" use the diff highlighting by default.
let g:gitgutter_enabled = 0
let g:gitgutter_highlight_lines = 1
" Open tagbar on the left, just like nerdtree
let g:tagbar_left = 1
" Have tagbar automatically focus and close once a tag is selected
let g:tagbar_autofocus = 1
let g:tagbar_autoclose = 1
" Sort by the order in the file, not by name
let g:tagbar_sort = 0
" Disable syntastic for HTML. It kind of sucks.
let syntastic_mode_map = { 'passive_filetypes': ['html'] }
" }}}
" Bundles {{{
" Initialize NeoBundle
if has('vim_starting')
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
call neobundle#begin(expand('~/.vim/bundle/'))
" Let NeoBundle manage itself
NeoBundleFetch 'Shougo/neobundle.vim'
" Use a bunch of sensible defaults for vim,
" approved the by the reverend Tim Pope
NeoBundle 'tpope/vim-sensible'
" The ever-famous, for fuzzy file searching
NeoBundle 'kien/ctrlp.vim'
" Indicate the diff of the file in the gutter
NeoBundle 'airblade/vim-gitgutter'
" Add amazing git integration
NeoBundle 'tpope/vim-fugitive'
" Easily manipulate surrounding pairs
NeoBundle 'tpope/vim-surround'
" Enable . for plugin mappings
NeoBundle 'tpope/vim-repeat'
" Add support for even more languages
NeoBundle 'sheerun/vim-polyglot'
" Add searching with ag
NeoBundle 'rking/ag.vim'
" Quickly maximize the current split
NeoBundle 'regedarek/ZoomWin'
" Auto-detect indentation settings
NeoBundle 'tpope/vim-sleuth'
" Add a beautiful and useful status bar
NeoBundle 'bling/vim-airline'
" Add .gitignore contents to wildignore
NeoBundle 'vim-scripts/gitignore'
" Quickly comment lines
NeoBundle 'scrooloose/nerdcommenter'
" Outline tags in a pane
NeoBundle 'majutsushi/tagbar'
" Add auto-closing of pairs for ruby and vim
NeoBundle 'tpope/vim-endwise'
" Show netrw in the current split.
NeoBundle 'tpope/vim-vinegar'
" Add support for easy alignment
NeoBundle 'junegunn/vim-easy-align'
" Add support for syntax error detection.
NeoBundle 'scrooloose/syntastic'
" Use Emmet for rapid HTML writing
NeoBundle 'mattn/emmet-vim'
" Highlight matching HTML tags.
NeoBundle 'Valloric/MatchTagAlways'
" Visually expand regions
NeoBundle 'terryma/vim-expand-region'
" Fold things
NeoBundle 'tmhedberg/SimpylFold'
call neobundle#end()
" Required:
filetype plugin indent on
" Let NeoBundle ensure everything is properly installed
NeoBundleCheck
" }}}