-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
333 lines (277 loc) · 10.3 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
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,perl,tex set shiftwidth=2
autocmd FileType c,cpp,java,javascript,python,xml,xhtml,html set shiftwidth=2
augroup filetypedetect
au! BufNewFile,BufRead *.ch setf cheat
au BufNewFile,BufRead *.liquid setf liquid
au! BufRead,BufNewFile *.haml setfiletype haml
autocmd BufNewFile,BufRead *.yml setf eruby
autocmd BufRead,BufNewFile *.prawn set filetype=ruby
autocmd BufRead,BufNewFile *.rsel set filetype=ruby
augroup END
" autocmd BufNewFile,BufRead *_test.rb source ~/.vim/ftplugin/shoulda.vim
autocmd BufNewFile,BufRead *.mxml compiler flex
au BufNewFile,BufRead *.mxml set filetype=mxml
au BufNewFile,BufRead *.as set filetype=actionscript
augroup END
autocmd BufNewFile,BufRead *_test.rb source ~/.vim/ftplugin/shoulda.vim
"use \rci in normal mode to indent ruby code,should install kode ,sudo gem
"install kode
nmap <leader>rci :%!ruby-code-indenter<cr>
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" Load matchit (% to bounce from do to end, etc.)
runtime! plugin/matchit.vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuffer Explorer Settings
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
" Command for spec execution with <leader>
let g:rubytest_cmd_spec = "spec -f specdoc %p"
" Change which file opens after executing :Rails command
let g:rails_default_file='config/database.yml'
set nocompatible " We're running Vim, not Vi!
"set guifont=Bitstream\ Vera\ Sans\ Mono\ 9
set guitablabel=%M%t
set nobackup
set noswapfile
set guifont=Monaco:h12
set guitablabel=%M%t
set nobackup
set nowritebackup
set path=$PWD/public/**,$PWD/**
filetype plugin indent on " Enable filetype-specific indenting and plugins
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
set guioptions-=m
set statusline=%<%f\ %h%m%r%=%-20.(line=%l,col=%c%V,totlin=%L%)\%h%m%r%=%-40(,%n%Y%)\%P
set laststatus=2
map <C-q> :mksession! ~/.vim/.session <cr>
map <C-//> map ,# :s/^/#/<CR>
map <S-//> :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR><Esc>:nohlsearch<CR>
imap <M-Up> :tabn<CR>
imap <M-Down> :tabp<CR>
imap <c-s> <esc><c-s>
"set guioptions-=T
set guioptions-=T
if has("gui_running")
"tell the term has 256 colors
set t_Co=256
colorscheme ir_black
set lines=40
set columns=115
else
let g:CSApprox_loaded = 0
colorscheme ir_black
endif
if $COLORTERM == 'gnome-terminal'
set term=ansi "gnome-256color
set term=gnome-256color
colorscheme ir_black
else
colorscheme ir_black
endif
syntax on " Enable syntax highlighting
" Load matchit (% to bounce from do to end, etc.)
runtime! macros/matchit.vim
set nonumber
augroup myfiletypes
" 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
augroup END
nmap <silent> <Leader>p :NERDTreeToggle<CR>
"make <c-l> clear the highlight as well as redraw
nnoremap <C-L> :nohls<CR><C-L>
inoremap <C-L> <C-O>:nohls<CR>
"map to bufexplorer
nnoremap <C-B> :BufExplorer<cr>
"map to fuzzy finder text mate stylez
nnoremap <c-f> :FuzzyFinderTextMate<CR>
"map Q to something useful
noremap Q gq
"make Y consistent with C and D
nnoremap Y y$
map <leader>b :FuzzyFinderBuffer<CR>
map <leader>] :FuzzyFinderMruFile<CR>
map <leader>r :ruby finder.rescan!<CR>
map ,t :Rake<CR>
let g:proj_flags="imstg"
let g:fuzzy_ceiling=20000
let g:fuzzy_matching_limit=25
let g:fuzzy_ignore = "gems/*, log/*"
set cursorline
"folding settings
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set wildmode=list:longest "make cmdline tab completion similar to bash
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
"vertical/horizontal scroll off settings
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
set cf " Enable error files & error jumping.
set clipboard+=unnamed " Yanks go on clipboard instead.
set history=256 " Number of things to remember in history.
set autowrite " Writes on make/shell commands
set ruler " Ruler on
set nu " Line numbers on
set nowrap " Line wrapping off
set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay)
" Formatting (some of these are for coding in C and C++)
set ts=2 " Tabs are 2 spaces
set bs=2 " Backspace over everything in insert mode
set shiftwidth=2 " Tabs under smart indent
set nocp incsearch
set cinoptions=:0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set formatoptions=tcqr
set cindent
set autoindent
set smarttab
set expandtab
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
let g:rubycomplete_rails = 1
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
" BEGIN rails-toolkit settings
runtime debian.vim
runtime macros/rails-toolkit.vim
" " END rails-toolkit setting
" Visual
set showmatch " Show matching brackets.
set mat=5 " Bracket blinking.
set list
" Show $ at end of line and trailing space as ~
set lcs=tab:\ \ ,extends:>,precedes:<
set novisualbell " No blinking .
set noerrorbells " No noise.
set laststatus=2 " Always show status line.
" gvim specific
set mousehide " Hide mouse after chars typed
"set mouse=a " Mouse in all modes
"visual search mappings
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
"jump to last cursor position when opening a file
"dont 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
"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
"define :HighlightExcessColumns command to highlight the offending parts of
"lines that are "too long". where "too long" is defined by &textwidth or an
"arg passed to the command
command! -nargs=? HighlightExcessColumns call s:HighlightExcessColumns('<args>')
function! s:HighlightExcessColumns(width)
let targetWidth = a:width != '' ? a:width : &textwidth
if targetWidth > 0
exec 'match Todo /\%>' . (targetWidth+1) . 'v/'
else
echomsg "HighlightExcessColumns: set a &textwidth, or pass one in"
endif
endfunction
"simple template system
command! -complete=customlist,<SID>AvailableTemplates -n=1
\ Template :call <SID>InsertTemplate('<args>')
function! <SID>InsertTemplate(name)
"read in the template
execute 'read ~/.vim/templates/' . &filetype . '/' . a:name
"if the cursor was previously on a blank line, delete it
if getline(line(".")-1) =~ '^\s*$'
exec line(".")-1 . 'd'
endif
endfunction
function! <SID>AvailableTemplates(lead, cmdline, cursorpos)
let templateDir = expand('~/.vim/templates/' . &filetype . '/')
let files = split(globpath(templateDir, a:lead . '*'), '\n')
"chop off the templateDir from each file
return map(files, 'strpart(v:val,strlen(templateDir))')
endfunction
" CTRL-R reloads the ~/.vimrc file
nnoremap <C-R> :source ~/.vimrc
inoremap <C-R> <C-O>:source ~/.vimrc
vnoremap <C-R> <C-C>:source ~/.vimrc
" reloads the snippets definitions
nnoremap <C-N> :source ~/.vim/after/plugin/snipMate.vim
inoremap <C-R> <C-O>:source ~/.vim/after/plugin/snipMate.vim
vnoremap <C-R> <C-C>:source ~/.vim/after/plugin/snipMate.vim
" CTRL-T and CTRL-D indent and unindent blocks
inoremap <C-D> <C-O><LT><LT>
nnoremap <C-D> <LT><LT>
vnoremap <C-T> >
vnoremap <C-D> <LT>
" CTRL-Z undoes even in visual/selection mode
vnoremap <C-Z> <C-C>
" Run Rspec for the current spec file
function! RunRspec()
ruby << EOF
buffer = VIM::Buffer.current
spec_file=VIM::Buffer.current.name
command = "ruby ~/.vim/bin/run_rspec.rb #{spec_file}"
print "Running Rspec for #{spec_file}. Results will be displayed in Firefox."
system(command)
EOF
endfunction
map <F7> :call RunRspec()<cr>
let g:browser = 'firefox -new-tab '
" Open the Ruby ApiDock page for the word under cursor, in a new Firefox tab
function! OpenRubyDoc(keyword)
let url = 'http://apidock.com/ruby/'.a:keyword
exec '!'.g:browser.' '.url.' &'
endfunction
noremap RB :call OpenRubyDoc(expand('<cword>'))<CR>
" Open the Rails ApiDock page for the word under cursos, in a new Firefox tab
function! OpenRailsDoc(keyword)
let url = 'http://apidock.com/rails/'.a:keyword
exec '!'.g:browser.' '.url.' &'
endfunction
noremap RR :call OpenRailsDoc(expand('<cword>'))<CR>
" Change the word under cursor
nmap ; :%s/\<<c-r>=expand("<cword>")<cr>\>/
" To save, ctrl-s.
nmap <c-s> :w<CR>
imap <c-s> <Esc>:w<CR>a
" Reload SnipMate snippets!!
function! ReloadSnippets( snippets_dir, ft )
if strlen( a:ft ) == 0
let filetype = "_"
else
let filetype = a:ft
endif
call ResetSnippets()
call GetSnippets( a:snippets_dir, filetype )
endfunction
nmap ,rr :call ReloadSnippets(snippets_dir, &filetype)<CR>