-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
250 lines (208 loc) · 7.03 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
" Use comma as leader
let mapleader = ","
" Use jj to switch to normal mode
:inoremap jj <esc>
""
"" Basic Setup
""
set nocompatible " Use vim, no vi defaults
set number " Show line numbers
set ruler " Show line and column number
syntax enable " Turn on syntax highlighting allowing local overrides
set encoding=utf-8 " Set default encoding to UTF-8
""
"" Whitespace
""
set nowrap " don't wrap lines
set tabstop=2 " a tab is two spaces
set shiftwidth=2 " an autoindent (with <<) is two spaces
set expandtab " use spaces, not tabs
set backspace=indent,eol,start " backspace through everything in insert mode
set showcmd " show length of visual selection @ bottom of screen
" Delete trailing whitespace on save
autocmd BufWritePre * :%s/\s\+$//e
" Use the same symbols as TextMate for tabstops and EOLs
set list listchars=tab:▸\ ,eol:¬
" Hide invisibles by default
set list!
""
"" Searching
""
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
"Textmate indentation shortcuts
nmap <D-[> <<
nmap <D-]> >>
vmap <D-[> <gv
vmap <D-]> >gv
"Mappings for moving between window 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
"Open vertical splits to the right
set splitright
""
"" File types
""
" Some file types should wrap their text
function! s:setupWrapping()
set wrap
set linebreak
set textwidth=72
set nolist
endfunction
filetype plugin indent on " Turn on filetype plugins (:help filetype-plugin)
if has("autocmd")
" In Makefiles, use real tabs, not tabs expanded to spaces
au FileType make set noexpandtab
" Set the Ruby filetype for a number of common Ruby files without .rb
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,Procfile,config.ru,*.rake} set ft=ruby
" Make sure all markdown files have the correct filetype set and setup wrapping
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} setf markdown | call s:setupWrapping()
" Treat JSON files like JavaScript
au BufNewFile,BufRead *.json set ft=javascript
" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ )
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79
" Syntax highlighting for handlebars templates using handlebars.vim
au BufRead,BufNewFile *.handlebars,*.hbs set ft=handlebars
" Remember last location in file, but not for commit messages.
" see :help last-position-jump
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
" Add spell checking and automatic wrapping at 72 columns to commit messages
autocmd Filetype gitcommit setlocal spell textwidth=72
endif
" % to bounce from do to end etc.
runtime! macros/matchit.vim
" Map ,e and ,v to edit or view files in same directory as current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
"
" CtrlP Mappings
"
" Open files with <leader>f
map <leader>f :CtrlP<cr>
" Open files, limited to the directory of the current file, with <leader>gf
" This requires the %% mapping found above.
map <leader>gf :CtrlP %%<cr>
" Rails-style mappings
map <leader>gm :CtrlP app/models<cr>
map <leader>gc :CtrlP app/controllers<cr>
map <leader>ge :CtrlP app/serializers<cr>
map <leader>gl :CtrlP app/validators<cr>
map <leader>gv :CtrlP app/views<cr>
map <leader>gy :CtrlP app/assets/stylesheets<cr>
map <leader>gs :CtrlP spec<cr>
map <leader>gj :CtrlP app/assets/javascripts<cr>
map <leader>gjm :CtrlP app/assets/javascripts/models<cr>
map <leader>gp :CtrlP app/assets/javascripts/web_components/polymer<cr>
"
" Functions
"
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'))
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>
function! RunCurrentTest()
" Write test file, then execute it.
:w
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
let path_to_current_file = expand('%')
let is_ruby_spec = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
if is_ruby_spec
exec '!zeus test ' . path_to_current_file
else
exec "!ruby spec/javascripts/support/compile_assets_and_run_test.rb %"
end
endfunction
map <leader>T :call RunCurrentTest()<cr>
function! RunCurrentTestAsync()
" Write test file, then execute it.
:w
let path_to_current_file = expand('%')
let is_ruby_spec = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
if is_ruby_spec
:!echo "zeus test %" > test-commands
else
:!echo "ruby spec/javascripts/support/compile_assets_and_run_test.rb %" > test-commands
end
endfunction
map <leader>t :call RunCurrentTestAsync()<cr><cr>
" re-set shell so that the function above executes with rvm ruby, not system
set shell=/bin/sh
"
" Colors
"
"Use 256 colors
set t_Co=256
colorscheme tir_black
" Supposed to speed up vim within tmux
set notimeout
set ttimeout
set timeoutlen=50
""
"" Mappings
""
" Press S to replace word under cursor with last yanked or deleted text
nnoremap S diw"0P"
" Toggle invisible characters
nmap <leader>l :set list!<cr>
""
"" Wild settings
""
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
" Ignore jasmine-headless-webkit cache
set wildignore+=.jhw-cache
""
"" Folding
""
set foldmethod=indent "fold based on indent
set foldnestmax=10 "deepest fold is 10 levels
set nofoldenable "dont fold by default
set foldlevel=1
""
"" Plug-In Config
""
" Ctrlp
let g:ctrlp_max_files=0
let g:ctrlp_max_depth=40
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$\|bower_components$\|dist$\|node_modules$\|tmp$'
\}
"
" Ack.vim
"
" use vanilla ack
let g:ackprg="ack -H --nocolor --nogroup --column --ignore-dir=public/assets"
" ..unless we have access to ag (The Silver Searcher), which is an order of
" magnitude faster
if executable('ag')
let g:ackprg = 'ag --nogroup --nocolor --column'
endif
" Vim Gutter
highlight clear SignColumn
" point Gbrowse to Bloomberg GH via vim-rhubarb
let g:github_enterprise_urls = ['https://bbgithub.dev.bloomberg.com']