-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
vimrc
346 lines (275 loc) · 9.17 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
" Detect Environment
let isGui = has("gui_running")
let isUnix = has("unix")
let isMac = has("mac")
filetype off
call pathogen#infect()
call pathogen#helptags()
" lots of those come from http://nvie.com/posts/how-i-boosted-my-vim/
set nocompatible
set virtualedit=
set nobackup
set nowritebackup
set noswapfile
set autoindent
set copyindent
set showmatch
set shiftround
set ruler
set scrolloff=4
set incsearch
set ignorecase
set smartcase
set backspace=2
set nu
set hidden
set mouse=a
" from: http://items.sjbach.com/319/configuring-vim-right
" set wildmenu
" scroll viewport faster
nnoremap <C-e> 5<C-e>
nnoremap <C-y> 5<C-y>
" limit "Press Enter or ... to continue"
set shortmess=atI
syn on
inoremap jk <Esc>
let mapleader=","
" Toggle highlight search
noremap <F2> :set hlsearch! hlsearch?<CR>
" Open file under cursor in new vertical split
map <F8> :vertical wincmd f<CR>
" Select different color for matching paren highlight
au Bufenter * silent! guibg=darkblue
" Keep small command-line window
set cmdheight=1
noremap <Space> A
imap <S-Space> <Esc>A
if(isGui)
colo wombat
else
colo wombat256mod
endif
set statusline=%f%m%r%h%w%<\ %{&ff}\ %Y\ %{fugitive#statusline()}\ %=%l/%L,%v\ %p%%
" Use Q for formatting the current paragraph (or selection)
vmap Q gq
nmap Q gqap
" sudo write open file
cmap w!! w !sudo tee % >/dev/null
" Editing and reloading vimrc
nmap <silent> <leader>ev :e $MYVIMRC <CR>
nmap <silent> <leader>sv :source $MYVIMRC<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" Restore cursor position to the last when file was open
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Font
if(isMac)
set gfn=Monaco:h16
else
set gfn=Courier:h16
endif
" Tagbar
map <silent> « :TagbarToggle<CR>
"
" Tabularize (format)
noremap <silent> <leader>f= :Tabularize /= <CR>
noremap <silent> <leader>f, :Tabularize /, <CR>
noremap <silent> <leader>f: :Tabularize /: <CR>
"Set tab size -- may be overridden for specific filetypes
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set nowrap
" Haskell specific
au FileType haskell compiler ghc
au FileType haskell noremap <leader>r :wa \| !runghc %<CR>
au FileType haskell noremap mm :wa \| !ghc -e :q %<CR>
au FileType haskell noremap <leader>m :wa \| !ghc -e runTests %<CR>
let g:haskell_indent_if = 4
let g:haskell_indent_case = 4
" quick way to get to Hoogle
au FileType haskell nmap __ _?1
" Configure browser for haskell_doc.vim
let g:haddock_browser = "open"
let g:haddock_browser_callformat = "%s %s"
" Yesod specific
au FileType hamlet set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" JavaScript specific
au FileType javascript noremap <leader>r :wa \| !export NODE_PATH="/Users/tlorenz/dev/lab49/landscape/trunk/packages" && node %<CR>
au FileType javascript noremap <leader>m :wa \| !mocha %<CR>
au FileType javascript set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType stylus set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType jade set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType handlebars set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType css set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType javascript nnoremap <leader>D :<C-u>call WriteJSDocComment()<CR>
" C specific
" au FileType c noremap <leader>r :wa \| make \| !./%:r<CR>
" C++ specific
set ut=100000
au FileType cpp,cc noremap <leader>r :<C-U>make %:r && ./%:r && rm ./%:r<CR>
" Python specific
au FileType python noremap <leader>r :wa \| !python %<CR>
au FileType python set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
"
" Java specific
au FileType java noremap mm :wa \| !javac %:p:h/*.java<CR>
" Turn Menu and toolbar off
set guioptions=-m
set guioptions=-M
" Turn scrollbars off
set guioptions-=r
set guioptions-=b
au FileType markdown set tabstop=2 softtabstop=2 shiftwidth=2
" Line numbers
nmap <leader>' :set relativenumber!<cr>
nmap <leader>" :set number!<cr>
"strip all trailing whitespace in the current file"
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
"Automatically remove trailing spaces"
au FileType c,cpp,java,php,js,py,coffee au BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
"Enable filtype plugins
filetype plugin on
filetype indent on
" Tab Navigation
map <C-j> :tabp<CR>
map <C-k> :tabn<CR>
" Buffer Explorer plugins
" don't override <leader>t which is I use for ctrlp
let g:buffergator_suppress_keymaps=1
" all we need is to toggle buffer pane since we don't use tabs
nnoremap <silent> <Leader>b :BuffergatorToggle<CR>
" alt+n or alt+p to navigate between entries in QuickFix
map <silent> <M-p> :cp <CR>
map <silent> <M-n> :cn <CR>
nmap <silent> <S-u> :GundoToggle <CR>
"Ruby
au FileType ruby,eruby set omnifunc=rubycomplete#Complete
au FileType ruby,eruby comp ruby
au FileType ruby mlet g:rubycomplete_buffer_loading = 1
au FileType ruby mlet g:rubycomplete_classes_in_global = 1
au FileType ruby map <F1> :!ri <CR>
au FileType ruby map <F3> :!irb<CR>
au FileType ruby noremap <leader>r !ruby %<CR>
" Flex/ActionScript
au FileType actionscript,mxml set omnifunc=actionscriptcomplete#Complete
"Auto Compile CoffeScript on save
if(isGui)
" Below prevents saving
let coffee_make_options = "-p"
au BufWritePost *.coffee silent CoffeeMake -b | cwindow
endif
" Minibuffer Explorer Settings
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
" Show $ at end of line and trailing space as ~
set lcs=tab:\ \ ,eol:$,trail:~,extends:>,precedes:<
set novisualbell " No blinking .
" No noise.
set noerrorbells
set visualbell t_vb=
set laststatus=2 " Always show status line.
" gvim specific
set mousehide " Hide mouse after chars typed
set mouse=a " Mouse in all modes
" FileUtils
" NerdTree
map <C-l> :NERDTreeToggle<CR>
" Close current buffer
map <silent> <leader>q :bd<CR>
" Write all then run spec for current dir
map <silent> ,s :wa \|S spec . --format progress <CR> <CR>
map <silent> ,; :wa \|! spec . --color --format specdoc <CR> <CR>
map <silent> ,: :wa \|! spec . --format html:spec/spec_report.html <CR> <CR>
" Open new terminal shell
map <leader>d :!zsh <CR>
" EasyGrep options
let g:EasyGrepFileAssociations='/Users/tlorenz/.vim/bundle/easygrep/plugin/EasyGrepFileAssociations'
let g:EasyGrepMode=0
let g:EasyGrepCommand=0
let g:EasyGrepRecursive=1
let g:EasyGrepIgnoreCase=1
let g:EasyGrepHidden=0
let g:EasyGrepSearchCurrentBufferDir=1
let g:EasyGrepAllOptionsInExplorer=1
let g:EasyGrepWindow=0
let g:EasyGrepReplaceWindowMode=0
let g:EasyGrepOpenWindowOnMatch=1
let g:EasyGrepEveryMatch=0
let g:EasyGrepJumpToMatch=1
let g:EasyGrepInvertWholeWord=0
let g:EasyGrepFileAssociationsInExplorer=0
let g:EasyGrepExtraWarnings=1
let g:EasyGrepOptionPrefix='<leader>vy'
let g:EasyGrepReplaceAllPerFile=0
" Quiet Lusty Juggler warnings that appear in sudo mode
let g:LustyExplorerSuppressRubyWarning = 1
" CtrlP options
let g:ctrlp_map = '<Leader>t'
let g:ctrlp_working_path_mode = 'r'
set wildignore+=*/dist/*,*/.git/*,*/.svn/*,*/dist/*,*.o,*.hi,*.sqlite3
" VCS specific
let g:VCSCommandDeleteOnHide=1
"Commands
command! -nargs=* Wrap set wrap linebreak nolist
"Shell inside Vim
command! -complete=shellcmd -nargs=+ S call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
let isfirst = 1
let words = []
for word in split(a:cmdline)
if isfirst
let isfirst = 0 " don't change first word (shell command)
else
if word[0] =~ '\v[%#<]'
let word = expand(word)
endif
let word = shellescape(word, 1)
endif
call add(words, word)
endfor
let expanded_cmdline = join(words)
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile wrap
call setline(1, expanded_cmdline)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !'. expanded_cmdline
resize 15
setlocal nomodifiable
endfunction
" Diff current Buffer with original file
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Enable Camel-Case search
nnoremap <expr> <leader>/ SearchCamelCase('/')
nnoremap <expr> <leader>? SearchCamelCase('?')
function! SearchCamelCase(dir)
call inputsave()
let ab = input(a:dir)
call inputrestore()
let l = filter(split(toupper(ab), '\zs'), 'v:val =~ "\\w"')
if len(l) > 0
let l[0] = '[' . l[0] . tolower(l[0]) . ']'
end
let @/ = '\C\<' . join(map(l, 'v:val . "[0-9a-z_]*"'), '') . '\>'
return a:dir . "\r"
endfunction
" different color scheme for markdown buffers
augroup filetype_colorscheme
au BufEnter *
\ if !exists('b:colors_name')
\ | if &ft == "markdown"
\ | let b:colors_name = 'wombat256mod'
\ | set tw=120 fo=cqt wm=0
\ | else
\ | let b:colors_name = 'wombat256mod'
\ | endif
\ | endif
\ | exe 'colorscheme' b:colors_name
augroup END