-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
183 lines (147 loc) · 4.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
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
call vundle#end()
filetype plugin indent on
Plugin 'VundleVim/Vundle.vim'
Plugin 'mileszs/ack.vim'
Plugin 'tpope/vim-haml'
Plugin 'godlygeek/tabular'
Plugin 'tpope/vim-rails'
Plugin 'vim-scripts/greplace.vim'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-fugitive'
Plugin 'vim-ruby/vim-ruby'
Plugin 'tpope/vim-endwise'
set nofoldenable
syntax enable
set autoindent
set softtabstop=2
set tabstop=2 shiftwidth=2 expandtab
set smartindent
set hlsearch
set nospell
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set incsearch
"set ignore case
set ic
"but use smart search - override rc when capitalization exists in the search
"term
set scs
set hidden
set list " show whitespace
set listchars=tab:»·,trail:· " show tabs and trailing spaces
set listchars+=extends:» " show a » when a line goes off the right
" edge of the screen
set listchars+=precedes:« " show a « when a line goes off the left
" edge of the screen
"needed to setup compatibility with rvm
set shell=sh
"speed up macros
set lazyredraw
"render long lines without too much slowdown
set synmaxcol=140
"kill old fugitive buffers
autocmd BufReadPost fugitive://* set bufhidden=delete
autocmd FileType ruby let b:dispatch = 'bundle exec rspec %'
let mapleader = ","
"Shorcuts to move around a split screen
map - <c-w>w
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-h> <c-w>h
map <c-l> <c-w>l
set statusline=%<%f\%h%m%r%=%-20.(line=%l\ \ col=%c%V\ \ totlin=%L%)\ \ \%h%m%r%=%-40(bytval=0x%B,%n%Y%)\%P
set laststatus=2
set number
set background=dark
vmap <Leader>g :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
" GUI is running or is about to start.
" Maximize gvim window.
if has("gui_running")
set lines=999 columns=999
endif
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
set directory=~/.vim/swapfiles,/var/tmp,/tmp,.
"map a to :Ack
nnoremap <leader>a :Ack
" shortcut to strip trailing whitespace
map <leader>s :s/\s\+$//g<CR>
nmap <leader>o o<esc>
nmap <leader>O O<esc>
""" Tabular
" sets ,= to align = and => lines
" sets ,; to align after the : in javscript objects
map <leader>= :Tabularize /=>\?<cr>
map <leader>; :Tabularize /:\zs /<cr>
map <leader>d :bp\|bd #<cr>
nnoremap <CR> :nohlsearch<cr>
nnoremap <silent> <Leader>+ :exe "vertical resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "vertical resize " . (winheight(0) * 2/3)<CR>
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
if match(a:filename, '\.feature$') != -1
exec ":!bundle exec cucumber " . a:filename
else
if filereadable("script/test")
exec ":!script/test " . a:filename
elseif filereadable("Gemfile")
exec ":!bundle exec rspec --color " . a:filename
else
exec ":!rspec --color " . a:filename
end
end
endfunction
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\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
map <leader>t :call RunTestFile()<cr>
" Run a given vim command on the results of fuzzy selecting from a given shell
" command. See usage below.
function! SelectaCommand(choice_command, selecta_args, vim_command)
try
let selection = system(a:choice_command . " | selecta " . a:selecta_args)
catch /Vim:Interrupt/
" Swallow the ^C so that the redraw below happens; otherwise there will be
" leftovers from selecta on the screen
redraw!
return
endtry
redraw!
exec a:vim_command . " " . selection
endfunction
function! ListActiveBuffers()
let bufferlist = []
for l:bni in range(bufnr("$"), 1, -1)
if buflisted(l:bni)
call add(bufferlist, bufname(l:bni))
endif
endfor
return "echo ".join(bufferlist, ' ')." | tr ' ' '\\n' "
endfunction
nnoremap <leader>b :exec SelectaCommand(ListActiveBuffers(), "", ":e")<cr>
" Find all files in all non-dot directories starting in the working directory.
" Fuzzy select one of those. Open the selected file with :e.
nnoremap <leader>f :call SelectaCommand("find * -type f -o -path 'vendor' -prune -type f -o -path 'tmp' -prune -type f", "", ":e")<cr>