forked from kerryb/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimrc
More file actions
458 lines (364 loc) · 12.9 KB
/
vimrc
File metadata and controls
458 lines (364 loc) · 12.9 KB
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
455
456
457
458
set nocompatible
call pathogen#infect()
filetype plugin indent on
syntax on
colorscheme darkermate
let mapleader = ","
" ----------------------------------------------
" Setup basic Vim behaviour
" ----------------------------------------------
set autoindent
set autowrite " Writes on make/shell commands
set backspace=start,indent,eol
set cf " Enable error files & error jumping.
set cursorline
set expandtab
set hidden " Allow buffer switching without saving
set history=1000 " Remember a decent way back
set laststatus=2 " Always show status line.
set mousehide
set nowrap " Line wrapping off
set number " line numbers
set ruler " Ruler on
set scrolloff=3 " More context around cursor
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
set shiftwidth=2
set smarttab
set statusline=%<%f\ %h%m%r%=%-20.(line=%l\ of\ %L,col=%c%V%)\%h%m%r%=%-40(,%n%Y%)\%P%#warningmsg#%{SyntasticStatuslineFlag()}%*
set tabstop=2
set timeoutlen=500
set wildmode=list:longest " Shell-like behaviour for command autocompletion
set fillchars+=vert:\ "Set the window borders to not have | chars in them
" GVim Options
set guioptions-=T " no toolbar
set guioptions-=m " no menu
set guioptions+=LlRrb " Hack which adds all scrollbars so that they can be removed, line below breaks without this
set guioptions-=LlRrb " Remove all scrollbars
" Search options
set hlsearch " highlight search matches...
set incsearch " ...as you type
set ignorecase
set smartcase
" ----------------------------------------------
" Command Shortcuts
" ----------------------------------------------
" make W and Q act like w and q
command! W :w
command! Q :q
" make Y consistent with C and D
nnoremap Y y$
" ,. to view all document buffers
nmap <silent> <unique> <Leader>. :BufExplorer<CR>
" ,, to run current spec file
" GUI vim does not appreciate terminal color codes
if has("gui_running")
map <Leader>, :wa\|!rspec --no-color %<CR>
else
map <Leader>, :wa\|!clear && rspec --color %<CR>
endif
" ,] to toggle the tags sidebar
nmap <Leader>] :TagbarToggle<CR>
" ,a<something> to align visually selected lines on <something>
vnoremap <silent> <Leader>a= :Align =<CR>
vnoremap <silent> <Leader>a=> :Align =><CR>
vnoremap <silent> <Leader>a, :Align ,<CR>
vnoremap <silent> <Leader>a{ :Align {<CR>
vnoremap <silent> <Leader>a<space> :Align " "<CR>
" ,a| to tabulate visually selected rows based on |
" Different from `:Align |` because it correctly spaces Cucumber table titles
vnoremap <silent> <Leader>a\| :call Tabularize('/\|/')<CR>
" ,c to show hidden characters
set listchars=tab:>-,trail:·,eol:$
nmap <silent> <leader>c :set nolist!<CR>
" ,f to clear cache and fuzzy search files; ,F in current file's directory
map <silent> <leader>f :ClearCtrlPCache<cr>\|:CtrlP<cr>
map <silent> <leader>F :ClearCtrlPCache<cr>\|:CtrlPCurFile<cr>
" ,g to jump to the next change since git commit
" ,G to jump to the last change since git commit
nmap <leader>g <Plug>GitGutterNextHunk
nmap <leader>G <Plug>GitGutterPrevHunk
" ,gt to toggle the gutter
nmap <leader>gt :GitGutterToggle<CR>
" ,gh yo highlight changed lines
nmap <leader>gh :GitGutterLineHighlightsToggle<CR>
map <Leader>1 :call RunCurrentSpecFile()<CR>
map <Leader>2 :call RunNearestSpec()<CR>
map <Leader>3 :call RunLastSpec()<CR>
map <Leader>4 :call RunAllSpecs()<CR>
" ,h to toggle search result highlighting
:noremap <silent> <leader>h :set hls!<CR>
" ,m to toggle file tree (,M to select the current file in the tree)
nmap <silent> <Leader>m :NERDTreeToggle<CR>
map <silent> <Leader>M :NERDTreeFind<CR>
" ,p to switch to better font for projector
noremap <silent> <leader>p :ToggleProjectorMode<CR>
" ,rt to run ctags on the current directory
map <leader>rt :!ctags -R .<CR><CR>
" ,s to toggle spelling highlighting
nmap <silent> <Leader>s :setlocal spell! spelllang=en_gb<CR>
" ,sw to strip whitespace off the ends
nmap <silent> <Leader>sw :call StripTrailingWhitespace()<CR>
" ,t to clear cache and fuzzy search files; ,T in current file's directory
" TO BE DEPRECATED FOR ,f and ,F
map <silent> <leader>t :ClearCtrlPCache<cr>\|:CtrlP<cr>
map <silent> <leader>T :ClearCtrlPCache<cr>\|:CtrlPCurFile<cr>
" ,u to toggle undo history browser
nnoremap <Leader>u :GundoToggle<CR>
" ,w to toggle line wrap
:map <silent> <Leader>w :set wrap!<CR>
" ,z to zoom pane when using splits
map <Leader>z :ZoomWin<CR>
" C-c to copy to the global buffer
vmap <A-c> "+y<CR>
" C-v to paste from the global buffer
map <A-v> "+p<CR>
" Ctrl+s to write the file (Will scroll-lock Vim in the terminal!)
map <C-s> <esc>:w<CR>
imap <C-s> <esc>:w<CR>
" Ctrl+\ to view the Vim style of the text under the cursor
nmap <C-\> :call <SID>SynStack()<CR>
" F5 to reload doc
map <silent> <F5> <esc>:e %<CR>
" Rebind half/fulll page scrolls to do 1 line at a time.
" Numbers are the Distance, Duraction and speed
noremap <silent> <c-u> :call smooth_scroll#up(&scroll, 20, 2)<CR>
noremap <silent> <c-d> :call smooth_scroll#down(&scroll, 20, 2)<CR>
noremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 20, 4)<CR>
noremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 20, 4)<CR>
" ----------------------------------------------
" Insert Mode Abbreviations
" ----------------------------------------------
" Try to auto-complete xml tags on typing '</'
iabbrev </ </<C-X><C-O>
" ----------------------------------------------
" Window split & size shortcuts
" ----------------------------------------------
" C-w s to vertical split
map <C-w>s :vsplit<CR>
" C-w S to horizontal split
map <C-w>S :split<CR>
" C-A-h and C-A-l to resize vertical split
map <C-A-h> :vertical resize -7<CR>
map <C-A-l> :vertical resize +7<CR>
" C-A-j and C-A-k to resize horizontal split
map <C-A-j> :resize -5<CR>
map <C-A-k> :resize +5<CR>
" C-H and C-L to jump left and right between splits
map <C-h> <C-w>h
map <C-l> <C-w>l
"
" C-J and C-K to jump down and up between splits
map <C-j> <C-w>j
map <C-k> <C-w>k
" ----------------------------------------------
" <ESC> Shortcuts
" ----------------------------------------------
imap jkl <ESC>
imap jlk <ESC>
imap kjl <ESC>
imap klj <ESC>
imap lkj <ESC>
imap ljk <ESC>
imap ;l <ESC>
imap jk <ESC>
imap kj <ESC>
" ----------------------------------------------
" Setup Misc Vim Behaviours
" ----------------------------------------------
" Setup the projector toggle plugin
let g:default_colorscheme = 'darkermate'
let g:projector_colorscheme = 'mac-classic'
" Display soft column limit in modern versions of vim
if version >= 730
au WinEnter,FileType * set cc=
au WinEnter,FileType ruby,eruby,rspec,cucumber set cc=140
endif
autocmd FileType make set noexpandtab
" Treat scss files as css
au BufRead,BufNewFile *.scss set filetype=css
" Extend % to do/end etc
runtime! plugin/matchit.vim
" Select a sensible font based on environment
if has('win32')
set guifont=Consolas\ 9
elseif has('mac')
set guifont=Menlo:h9
else
"set guifont=Source\ Code\ Pro\ 10
set guifont=DejaVu\ Sans\ Mono\ 9
" if you don't have these fonts, set one here or in your vim.local file
endif
" Ruby debugger settings
if has('gui')
if has("mac")
let g:ruby_debugger_progname = 'mvim'
else
let g:ruby_debugger_progname = 'gvim'
endif
map <Leader>dg :Rdebugger<CR>
map <Leader>dr :RdbTest<CR>
endif
" Fix supertab/endwise incompatibility
let g:SuperTabCrMapping = 0
" Highlight trailing whitespace
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
let g:ragtag_global_maps = 1
" A whole bunch of NERDTree configuration stolen from carlhuda's janus
let NERDTreeIgnore=['\.rbc$', '\~$']
" Make NERDTree close when you open a file from it. Helps recover screen
" space!
let NERDTreeQuitOnOpen=1
" Disable netrw's autocmd, since we're ALWAYS using NERDTree
runtime plugin/netRwPlugin.vim
augroup FileExplorer
au!
augroup END
let g:NERDTreeHijackNetrw = 0
" If the parameter is a directory (or there was no parameter), open NERDTree
function s:NERDTreeIfDirectory(directory)
if isdirectory(a:directory) || a:directory == ""
NERDTree
endif
endfunction
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
if isdirectory(a:directory)
call ChangeDirectory(a:directory)
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(stay)
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
NERDTree
if !a:stay
wincmd p
end
endif
endif
endfunction
" Utility functions to create file commands
function s:CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction
function s:FileCommand(name, ...)
if exists("a:1")
let funcname = a:1
else
let funcname = a:name
endif
execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
endfunction
function s:DefineCommand(name, destination)
call s:FileCommand(a:destination)
call s:CommandCabbr(a:name, a:destination)
endfunction
" Public NERDTree-aware versions of builtin functions
function ChangeDirectory(dir, ...)
execute "cd " . a:dir
let stay = exists("a:1") ? a:1 : 1
call s:UpdateNERDTree(stay)
endfunction
function Touch(file)
execute "!touch " . a:file
call s:UpdateNERDTree(1)
endfunction
function Remove(file)
let current_path = expand("%")
let removed_path = fnamemodify(a:file, ":p")
if (current_path == removed_path) && (getbufvar("%", "&modified"))
echo "You are trying to remove the file you are editing. Please close the buffer first."
else
execute "!rm " . a:file
endif
endfunction
function Edit(file)
if exists("b:NERDTreeRoot")
wincmd p
endif
execute "e " . a:file
ruby << RUBY
destination = File.expand_path(VIM.evaluate(%{system("dirname " . a:file)}))
pwd = File.expand_path(Dir.pwd)
home = pwd == File.expand_path("~")
if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
VIM.command(%{call ChangeDirectory(system("dirname " . a:file), 0)})
end
RUBY
endfunction
" Define the NERDTree-aware aliases
call s:DefineCommand("cd", "ChangeDirectory")
call s:DefineCommand("touch", "Touch")
call s:DefineCommand("rm", "Remove")
"call s:DefineCommand("e", "Edit") " if you don't mind not being able to "e!"
" Jump to last cursor position when opening a file
" Don't do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal g`\""
endif
end
endfunction
" strip trailing whitespace<foo&bar>
"autocmd BufWritePre,FileWritePre * call StripTrailingWhitespace()
function! StripTrailingWhitespace()
normal mz
normal Hmy
exec '%s/\s*$//g'
normal 'yz<cr>
normal `z
endfunction
let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list=1
" Add function for showing the syntax tag for the selected text
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
"define :Lorem command to dump in a paragraph of lorem ipsum
command! -nargs=0 Lorem :normal iLorem ipsum dolor sit amet, consectetur
\ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
\ magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
\ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
\ irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
\ fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
\ proident, sunt in culpa qui officia deserunt mollit anim id est
\ laborum
" Automatically turn on colorizers highlighting for some filetypes
let g:colorizer_auto_filetype='css,html,less,scss,vim'
" Make colorizer play nicely with 2html
let g:colorizer_syntax = 1
" Enable wrapping when editing text documents (eg Markdown)
autocmd BufNewFile,BufRead *.md :setlocal wrap
" Setup relative number toggle on Ctrl+n
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <C-n> :call NumberToggle()<cr>
" Ignores files in any VCS or tmp directory
set wildignore+=tmp/*,*.so,*.swp,*.zip
" ----------------------------------------------
" Set the git gutter colors to be the same as the number column
" ----------------------------------------------
hi clear SignColumn
" Set the Gutter to show all the time, avoiding the column 'pop' when saving
let g:gitgutter_sign_column_always = 1
" Vroom settings
let g:vroom_write_all = 1
let g:vroom_cucumber_path = 'cucumber '
" ----------------------------------------------
" Source any local config
" Keep this last to make sure local config overrides global!
" ----------------------------------------------
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif