-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
384 lines (314 loc) · 10.7 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
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
" This must be first, because it changes other options as a side effect.
set nocompatible " We're running Vim, not Vi!
filetype off " Only temporarily while we load pathogen...
" Load Vundle
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Bundle "git://github.com/tpope/vim-fugitive.git"
Bundle "git://github.com/tpope/vim-git.git"
Bundle "kien/ctrlp.vim"
Bundle "scrooloose/nerdtree"
Bundle "git://github.com/tpope/vim-repeat.git"
Bundle "git://github.com/tpope/vim-surround.git"
Bundle "git://github.com/tpope/vim-vividchalk.git"
Bundle "git://github.com/vim-ruby/vim-ruby.git"
Bundle "git://github.com/tpope/vim-haml.git"
Bundle "https://github.com/kchmck/vim-coffee-script.git"
Bundle "https://github.com/tpope/vim-rails.git"
Bundle "git://github.com/altercation/vim-colors-solarized.git"
Bundle "https://github.com/jgdavey/vim-railscasts.git"
Bundle "https://github.com/mileszs/ack.vim"
Bundle "https://github.com/Lokaltog/vim-powerline"
Bundle "https://github.com/othree/html5.vim"
Bundle "https://github.com/tpope/vim-markdown.git"
Bundle "https://github.com/vim-scripts/mayansmoke"
Bundle "git://github.com/tpope/vim-endwise.git"
Bundle "https://github.com/kien/rainbow_parentheses.vim"
Bundle "[email protected]:elixir-lang/vim-elixir.git"
call vundle#end() " required
filetype plugin indent on " required
let mapleader = ","
" disallow vi commands from files
set modelines=0
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :split $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" jump to far right or left of line
map L $
map H ^
" borrowed from the Janus vimrc
" seemingly necessary for zoomwin
set noequalalways
" Ctrl-P config
let g:path_to_matcher = "/Users/paulhenrich/bin/matcher"
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files . -co --exclude-standard']
let g:ctrlp_match_func = { 'match': 'GoodMatch' }
function! GoodMatch(items, str, limit, mmode, ispath, crfile, regex)
" Create a cache file if not yet exists
let cachefile = ctrlp#utils#cachedir().'/matcher.cache'
if !( filereadable(cachefile) && a:items == readfile(cachefile) )
call writefile(a:items, cachefile)
endif
if !filereadable(cachefile)
return []
endif
" a:mmode is currently ignored. In the future, we should probably do
" something about that. the matcher behaves like "full-line".
let cmd = g:path_to_matcher.' --limit '.a:limit.' --manifest '.cachefile.' '
if !( exists('g:ctrlp_dotfiles') && g:ctrlp_dotfiles )
let cmd = cmd.'--no-dotfiles '
endif
let cmd = cmd.a:str
return split(system(cmd), "\n")
endfunction
map <c-t> :CtrlP<CR>
map <leader>t :CtrlP<CR>
" async rspec
map <leader>s :w\|:silent !echo "clear; rspec --color %" > test-commands<cr>
map <leader>r :w\|!rspec %<cr>
"" test runner from gbh
function! MapCR()
nnoremap <cr> :call RunTestFile()<cr>
endfunction
call MapCR()
nnoremap <leader>T :call RunNearestTest()<cr>
"" nnoremap <leader>r :call RunTests('')<cr>
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Are we in a test file?
let in_test_file = match(expand("%"), '\(_spec.rb\|_test.rb\|test_.*\.py\|_test.py\)$') != -1
" Run the tests for the previously-marked file (or the current file if
" it's a test).
if in_test_file
call SetTestFile(command_suffix)
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number)
endfunction
function! SetTestFile(command_suffix)
" Set the spec file that tests will be run for.
let t:grb_test_file=@% . a:command_suffix
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
if expand("%") != ""
:w
end
" The file is executable; assume we should run
if executable(a:filename)
exec ":!./" . a:filename
" Project-specific test script
elseif filereadable("script/test")
exec ":!script/test " . a:filename
" Fall back to the .test-commands pipe if available, assuming someone
" is reading the other side and running the commands
elseif filewritable(".test-commands")
let cmd = 'rspec --color --format progress --require "~/lib/vim_rspec_formatter" --format VimFormatter --out tmp/quickfix'
exec ":!echo " . cmd . " " . a:filename . " > .test-commands"
" Write an empty string to block until the command completes
sleep 100m " milliseconds
:!echo > .test-commands
redraw!
" Fall back to a blocking test run with Bundler
elseif filereadable("bin/rspec")
exec ":!bin/rspec --color " . a:filename
elseif filereadable("Gemfile") && strlen(glob("spec/**/*.rb"))
exec ":!bundle exec rspec --color " . a:filename
elseif filereadable("Gemfile") && strlen(glob("test/**/*.rb"))
exec ":!bin/rails test " . a:filename
" If we see python-looking tests, assume they should be run with Nose
elseif strlen(glob("test/**/*.py") . glob("tests/**/*.py"))
exec "!nosetests " . a:filename
end
endfunction
" ZoomWin configuration
map <Leader>z :ZoomWin<CR>
" bounce to test
map <leader>a :A<cr>
" Bits stolen from Gary Bernhardt
" bounce buffer
nnoremap <leader><leader> <c-^>
" RENAME CURRENT FILE
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Ack
map <Leader>g :!git grep<space>
" lazy escape
imap jj <Esc>
" keep more history
set history=100
" resize splits sensibly
set winwidth=100
set winminwidth=35
" show hidden buffers
set hidden
" don't beep
set visualbell
set noerrorbells
" numbers, we like them
set number
" Syntax highlighting
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
" sync syntax from the start of the file
syntax sync fromstart
set hlsearch
endif
"ColorScheme if terminal has colors (not in GUI)
if (&t_Co > 7)
set bg=dark
colorscheme wombat256
"colorscheme summerfruit256
"assume we can use !open
map <Leader>o :w\|:!open %<CR>
endif
map <Leader><Leader> :w\|:!./%<CR>
" Indentation and Tab handling
set smarttab
set expandtab
set autoindent
set shiftwidth=2
set tabstop=2
set autoindent smartindent
" Line Wrapping
set nowrap
set linebreak " Wrap at word
" Search results
set incsearch " incremental searching
set ignorecase " case insensitive searching
set smartcase
" Toggle search results with spacebar
map <Space> :set hlsearch!<cr>
" catch trailing whitespace
set listchars=tab:>-,trail:·,eol:$
"nmap <silent> <leader>s :set nolist!<CR>
" Swapfiles. Meh. Using Git instead.
set nobackup
set noswapfile
set nowritebackup
" show incomplete commands
set showcmd
" Split windows behavior
set splitbelow
set splitright
" kill the splash screen
set shortmess=atI
set ruler
set undolevels=1000
set scrolloff=3
set showmatch
set wildmenu
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
autocmd!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
"augroup myfiletypes "forget this... make exceptions per directory below &
"per file with modelines.
"" Clear old autocmds in group
"autocmd!
"" autoindent with two spaces, always expand tabs
"autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
"autocmd FileType javascript set ai sw=2 sts=2 et
"autocmd FileType php set ai noet
"augroup END
autocmd FileType markdown set wrap
augroup module
autocmd BufRead *.module set filetype=php
augroup END
augroup inc
autocmd BufRead *.inc set filetype=php
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Load matchit (% to bounce from do to end, etc.)
runtime! macros/matchit.vim
" Status line configuration (from tomasr)
" ---------------------------------------
set laststatus=2 " Always show status line
if has('statusline')
" Status line detail:
" %f file path
" %y file type between braces (if defined)
" %([%R%M]%) read-only, modified and modifiable flags between braces
" %{'!'[&ff=='default_file_format']}
" shows a '!' if the file format is not the platform
" default
" %{'$'[!&list]} shows a '*' if in list mode
" %{'~'[&pm=='']} shows a '~' if in patchmode
" (%{synIDattr(synID(line('.'),col('.'),0),'name')})
" only for debug : display the current syntax item name
" %= right-align following items
" #%n buffer number
" %l/%L,%c%V line number, total number of lines, and column number
fun! SetStatusLineStyle()
if &stl == '' || &stl =~ 'synID'
let &stl="%f %y%([%R%M]%)%{'!'[&ff=='".&ff."']}%{'$'[!&list]}%{'~'[&pm=='']}%{fugitive#statusline()}%=#%n %l/%L,%c%V "
else
let &stl="%f %y%([%R%M]%)%{'!'[&ff=='".&ff."']}%{'$'[!&list]} (%{synIDattr(synID(line('.'),col('.'),0),'name')})%=#%n %l/%L,%c%V "
endif
endfunc
" Switch between the normal and vim-debug modes in the status line
nmap _ds :call SetStatusLineStyle()<CR>
call SetStatusLineStyle()
" Window title
if has('title')
set titlestring=%t%(\ [%R%M]%)
endif
endif
" up/down move between visual lines instead of actual lines when wrapped
imap <silent> <Down> <C-o>gj
imap <silent> <Up> <C-o>gk
nmap <silent> <Down> gj
nmap <silent> <Up> gk
nmap <silent> j gj
nmap <silent> k gk
" move 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
" pinky saving remap;
nnoremap ; :
"Rainbow parens
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces