-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
250 lines (211 loc) · 8.09 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
set nocompatible " Must come first because it changes other options.
filetype off " Necessary on some Linux distros for pathogen to properly load bundles
" *********************************************
" * Vundle - Vim Plugins *
" *********************************************
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" Let Vundle manage Vundle
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-rake'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-endwise'
Bundle 'scrooloose/nerdtree'
Bundle 'kien/ctrlp.vim'
Bundle 'msanders/snipmate.vim'
Bundle 'ervandew/supertab'
Bundle 'mileszs/ack.vim'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/syntastic'
Bundle 'Raimondi/delimitMate'
Bundle 'mattn/zencoding-vim'
Bundle 'vim-scripts/IndexedSearch'
Bundle 'vim-scripts/L9.git'
Bundle 'vim-scripts/lh-vim-lib'
Bundle 'vim-scripts/matchit.zip'
Bundle 'godlygeek/tabular'
Bundle 'git://gist.github.com/287147.git'
Bundle 'tpope/vim-cucumber'
Bundle 'tpope/vim-haml'
Bundle 'pangloss/vim-javascript'
Bundle 'kchmck/vim-coffee-script'
Bundle 'groenewege/vim-less.git'
Bundle 'digitaltoad/vim-jade.git'
" *********************************************
" * Settings *
" *********************************************
set encoding=utf-8
syntax enable
filetype plugin indent on " load file type plugins + indentation
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set showmatch " Show matching brackets/parenthesis
set nowrap " don't wrap lines
set tabstop=2 shiftwidth=2 " a tab is two spaces (or set this to 4)
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in insert mode"
set autoindent " match indentation of previous line
set pastetoggle=<F2>
set incsearch " Find as you type search
set hlsearch " Highlight search terms
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set hidden " Handle multiple buffers better.
set title " Set the terminal's title
set number " Show line numbers.
set ruler " Show cursor position.
set wildmode=list:longest " Complete files like a shell.
set wildmenu " Enhanced command line completion.
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set novisualbell
set noerrorbells
set history=10000 " Store lots of :cmdline history
set scrolloff=3
set sidescrolloff=7
set mouse-=a
set mousehide
set ttymouse=xterm2
set sidescroll=1
set nobackup " Don't make a backup before overwriting a file.
set nowritebackup " And again.
set directory=/tmp " Keep swap files in one location
set timeoutlen=500
set laststatus=2 " Show the status line all the time
set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P
set t_Co=256 " Set terminal to 256 colors
set background=dark
colorscheme railscasts
" *********************************************
" * Key Bindings *
" *********************************************
let mapleader = ","
" Clear last search highlighting
nnoremap <Space> :noh<cr>
" Easier navigation between split windows
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" Insert blank lines without going into insert mode
nmap go o<esc>
nmap gO O<esc>
" Shortcut for =>
imap <C-l> <Space>=><Space>
" F7 reformats the whole file and leaves you where you were (unlike gg)
map <silent> <F7> mzgg=G'z :delmarks z<CR>:echo "Reformatted."<CR>")
cnoremap $$ <C-R>=expand("\"" . VisualSelection() . "\"")<cr>
" OPEN FILES IN DIRECTORY OF CURRENT FILE
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
" 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
exec ':e ' . new_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIT GREP
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Function: lh#visual#selection()
" @return the text currently selected
function! VisualSelection()
try
let a_save = @a
normal! gv"ay
return @a
finally
let @a = a_save
endtry
endfunction
function! GitGrep()
"let [lnum1, col1] = getpos("'<")[1:2]
"let [lnum2, col2] = getpos("'>")[1:2]
"let lines = getline(lnum1, lnum2)
"let lines[-1] = lines[-1][: col2 - 1]
"let lines[0] = lines[0][col1 - 1:]
exec ":!git grep \"" . VisualSelection() . "\""
endfunction
map <leader>g :call GitGrep()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This makes RVM work inside Vim. I have no idea why.
set shell=bash
map <leader>t :call RunTestFile()<cr>
map <leader>T :call RunNearestTest()<cr>
map <leader>a :call RunTests('')<cr>
map <leader>c :w\|:!script/features<cr>
map <leader>w :w\|:!script/features --profile wip<cr>
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Run the tests for the previously-marked file.
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|Spec.js\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
: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
if match(a:filename, '\.feature$') != -1
exec ":!time script/features " . a:filename
else
if filereadable("script/test")
echo "script/test"
exec ":!time script/test " . a:filename
elseif filereadable("Gemfile")
exec ":!time bundle exec rspec --color " . a:filename
else
exec ":!time rspec --color " . a:filename
end
end
endfunction
" *********************************************
" * Plugin Customization *
" *********************************************
"# ctrlp.vim
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " for Linux/MacOSX
" Find unused cucumber steps.
command! CucumberFindUnusedSteps :call CucumberFindUnusedSteps()
function! CucumberFindUnusedSteps()
let olderrorformat = &l:errorformat
try
set errorformat=%m#\ %f:%l
cexpr system('bundle exec cucumber --no-profile --no-color --format usage --dry-run features \| grep "NOT MATCHED BY ANY STEPS" -B1 \| egrep -v "(--\|NOT MATCHED BY ANY STEPS)"')
cwindow
finally
let &l:errorformat = olderrorformat
endtry
endfunction