Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 604 lines (501 sloc) 17.374 kb
6bbee6c @garybernhardt Added a proper top comment to .vimrc
authored
1 " This is Gary Bernhardt's .vimrc file
d9da825 @garybernhardt Initial commit
authored
2 "
6bbee6c @garybernhardt Added a proper top comment to .vimrc
authored
3 " Be warned: this has grown slowly over years and may not be internally
4 " consistent.
d9da825 @garybernhardt Initial commit
authored
5
6 " When started as "evim", evim.vim will already have done these settings.
7 if v:progname =~? "evim"
8 finish
9 endif
10
11 " Use Vim settings, rather then Vi settings (much better!).
12 " This must be first, because it changes other options as a side effect.
13 set nocompatible
14
15 " Allow backgrounding buffers without writing them, and remember marks/undo
16 " for backgrounded buffers
17 set hidden
18
19 " Remember more commands and search history
20 set history=1000
21
22 " Make tab completion for files/buffers act like bash
23 set wildmenu
24
25 " Make searches case-sensitive only if they contain upper-case characters
26 set ignorecase
27 set smartcase
28
29 " Keep more context when scrolling off the end of a buffer
30 set scrolloff=3
31
32 " Store temporary files in a central spot
33 set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
34 set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
35
36 " allow backspacing over everything in insert mode
37 set backspace=indent,eol,start
38
39 if has("vms")
40 set nobackup " do not keep a backup file, use versions instead
41 else
42 set backup " keep a backup file
43 endif
44 set ruler " show the cursor position all the time
45 set showcmd " display incomplete commands
46
47 " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
48 " let &guioptions = substitute(&guioptions, "t", "", "g")
49
50 " Don't use Ex mode, use Q for formatting
51 map Q gq
52
53 " This is an alternative that also works in block mode, but the deleted
54 " text is lost and it only works for putting the current register.
55 "vnoremap p "_dp
56
57 " Switch syntax highlighting on, when the terminal has colors
58 " Also switch on highlighting the last used search pattern.
59 if &t_Co > 2 || has("gui_running")
60 syntax on
61 set hlsearch
e886c4b @garybernhardt Switched vim to inconsolata font
authored
62 " set guifont=Monaco:h14
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
63 set guifont=Inconsolata-dz:h14
d9da825 @garybernhardt Initial commit
authored
64 endif
65
66 " Only do this part when compiled with support for autocommands.
67 if has("autocmd")
68
69 " Enable file type detection.
70 " Use the default filetype settings, so that mail gets 'tw' set to 72,
71 " 'cindent' is on in C files, etc.
72 " Also load indent files, to automatically do language-dependent indenting.
73 filetype plugin indent on
74
75 " Put these in an autocmd group, so that we can delete them easily.
76 augroup vimrcEx
77 au!
78
79 " For all text files set 'textwidth' to 78 characters.
80 autocmd FileType text setlocal textwidth=78
81
82 " When editing a file, always jump to the last known cursor position.
83 " Don't do it when the position is invalid or when inside an event handler
84 " (happens when dropping a file on gvim).
85 autocmd BufReadPost *
86 \ if line("'\"") > 0 && line("'\"") <= line("$") |
87 \ exe "normal g`\"" |
88 \ endif
89
90 augroup END
91
92 else
93
94 set autoindent " always set autoindenting on
95
96 endif " has("autocmd")
97
98
99 " GRB: sane editing configuration"
100 set expandtab
101 set tabstop=4
102 set shiftwidth=4
103 set softtabstop=4
104 set autoindent
105 " set smartindent
106 set laststatus=2
107 set showmatch
108 set incsearch
109
110 " GRB: wrap lines at 78 characters
7cac8f3 @garybernhardt highlight long lines in red
authored
111 " set textwidth=78
112
113 " GRB: Highlight long lines
1dc7fb0 @garybernhardt complicate long line highlights because Vim sucks
authored
114 " Turn long-line highlighting off when entering all files, then on when
115 " entering certain files. I don't understand why :match is so stupid that
116 " setting highlighting when entering a .rb file will cause e.g. a quickfix
117 " window opened later to have the same match. There doesn't seem to be any way
118 " to localize it to a file type.
68afcd5 @garybernhardt comment out long line highlight for the nth time
authored
119 " function! HighlightLongLines()
120 " hi LongLine guifg=NONE guibg=NONE gui=undercurl ctermfg=white ctermbg=red cterm=NONE guisp=#FF6C60 " undercurl color
121 " endfunction
122 " function! StopHighlightingLongLines()
123 " hi LongLine guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE guisp=NONE
124 " endfunction
125 " autocmd TabEnter,WinEnter,BufWinEnter * call StopHighlightingLongLines()
126 " autocmd TabEnter,WinEnter,BufWinEnter *.rb,*.py call HighlightLongLines()
127 " hi LongLine guifg=NONE
128 " match LongLine '\%>78v.\+'
d9da825 @garybernhardt Initial commit
authored
129
130 " GRB: highlighting search"
131 set hls
132
133 if has("gui_running")
134 " GRB: set font"
135 ":set nomacatsui anti enc=utf-8 gfn=Monaco:h12
136
137 " GRB: set window size"
138 :set lines=100
d87898b @garybernhardt Widened vim window to make room for cyclomatic complexity annotations
authored
139 :set columns=171
d9da825 @garybernhardt Initial commit
authored
140
141 " GRB: highlight current line"
142 :set cursorline
143 endif
144
145 " GRB: set the color scheme
09c5439 @garybernhardt switch to 256-color terminal and vim color scheme
authored
146 :set t_Co=256 " 256 colors
147 :color grb256
d9da825 @garybernhardt Initial commit
authored
148
13e4d88 @garybernhardt Merged .gvimrc into .vimrc
authored
149 " GRB: hide the toolbar in GUI mode
150 if has("gui_running")
151 set go-=T
152 end
153
d9da825 @garybernhardt Initial commit
authored
154 " GRB: add pydoc command
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
155 :command! -nargs=+ Pydoc :call ShowPydoc("<args>")
156 function! ShowPydoc(module, ...)
157 let fPath = "/tmp/pyHelp_" . a:module . ".pydoc"
158 :execute ":!pydoc " . a:module . " > " . fPath
159 :execute ":sp ".fPath
160 endfunction
d9da825 @garybernhardt Initial commit
authored
161
162 " GRB: Always source python.vim for Python files
163 au FileType python source ~/.vim/scripts/python.vim
164
165 " GRB: Use custom python.vim syntax file
166 au! Syntax python source ~/.vim/syntax/python.vim
167 let python_highlight_all = 1
168 let python_slow_sync = 1
169
170 " GRB: use emacs-style tab completion when selecting files, etc
171 set wildmode=longest,list
172
173 " GRB: Put useful info in status line
8712bc6 @garybernhardt add file modification indicator to status line
authored
174 :set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
d9da825 @garybernhardt Initial commit
authored
175 :hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red
176
177 " GRB: clear the search buffer when hitting return
4dd9a59 @garybernhardt remove PressedEnter vim function
authored
178 :nnoremap <CR> :nohlsearch<cr>
d9da825 @garybernhardt Initial commit
authored
179
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
180 " Remap the tab key to do autocompletion or indentation depending on the
181 " context (from http://www.vim.org/tips/tip.php?tip_id=102)
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
182 function! InsertTabWrapper()
183 let col = col('.') - 1
184 if !col || getline('.')[col - 1] !~ '\k'
185 return "\<tab>"
186 else
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
187 return "\<c-p>"
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
188 endif
189 endfunction
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
190 inoremap <tab> <c-r>=InsertTabWrapper()<cr>
191 inoremap <s-tab> <c-n>
192
07d4301 @garybernhardt Added snipMate bound to the ; key in vim
authored
193 " When hitting <;>, complete a snippet if there is one; else, insert an actual
194 " <;>
195 function! InsertSnippetWrapper()
196 let inserted = TriggerSnippet()
197 if inserted == "\<tab>"
198 return ";"
199 else
200 return inserted
201 endif
202 endfunction
203 inoremap ; <c-r>=InsertSnippetWrapper()<cr>
204
d9da825 @garybernhardt Initial commit
authored
205 if version >= 700
206 autocmd FileType python set omnifunc=pythoncomplete#Complete
207 let Tlist_Ctags_Cmd='~/bin/ctags'
208 endif
209
7e4384c @garybernhardt Added more ways to run tests in vim
authored
210 function! RunTests(target, args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
211 silent ! echo
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
212 exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
b54f0e6 @garybernhardt Made test running from vim fancier
authored
213 silent w
62ff89d @garybernhardt Improved test behavior in MacVim
authored
214 exec "make " . a:target . " " . a:args
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
215 endfunction
216
217 function! ClassToFilename(class_name)
218 let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
219 let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
220 return file_name
221 endfunction
222
223 function! ModuleTestPath()
224 let file_path = @%
225 let components = split(file_path, '/')
226 let path_without_extension = substitute(file_path, '\.py$', '', '')
2c67ca3 @garybernhardt Removed old BitBacker-specific stuff in Python test running vim code
authored
227 let test_path = 'tests/unit/' . path_without_extension
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
228 return test_path
229 endfunction
230
231 function! NameOfCurrentClass()
232 let save_cursor = getpos(".")
233 normal $<cr>
234 call PythonDec('class', -1)
235 let line = getline('.')
236 call setpos('.', save_cursor)
237 let match_result = matchlist(line, ' *class \+\(\w\+\)')
238 let class_name = ClassToFilename(match_result[1])
239 return class_name
240 endfunction
241
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
242 function! TestFileForCurrentClass()
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
243 let class_name = NameOfCurrentClass()
244 let test_file_name = ModuleTestPath() . '/test_' . class_name . '.py'
245 return test_file_name
246 endfunction
247
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
248 function! TestModuleForCurrentFile()
249 let test_path = ModuleTestPath()
250 let test_module = substitute(test_path, '/', '.', 'g')
251 return test_module
252 endfunction
253
7e4384c @garybernhardt Added more ways to run tests in vim
authored
254 function! RunTestsForFile(args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
255 if @% =~ 'test_'
7e4384c @garybernhardt Added more ways to run tests in vim
authored
256 call RunTests('%', a:args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
257 else
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
258 let test_file_name = TestModuleForCurrentFile()
7e4384c @garybernhardt Added more ways to run tests in vim
authored
259 call RunTests(test_file_name, a:args)
f03120a @garybernhardt Added proper handling of all tests passing in vim
authored
260 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
261 endfunction
262
7e4384c @garybernhardt Added more ways to run tests in vim
authored
263 function! RunAllTests(args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
264 silent ! echo
265 silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
266 silent w
b7c24b5 @garybernhardt Vim test running hackery. Good luck to anyone trying to duplicate it now...
authored
267 exec "make!" . a:args
7e4384c @garybernhardt Added more ways to run tests in vim
authored
268 endfunction
269
270 function! JumpToError()
271 if getqflist() != []
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
272 for error in getqflist()
273 if error['valid']
274 break
275 endif
276 endfor
277 let error_message = substitute(error['text'], '^ *', '', 'g')
9fb3a39 @garybernhardt Re-enabled jumping to the erroring line when running tests
authored
278 silent cc!
2c67ca3 @garybernhardt Removed old BitBacker-specific stuff in Python test running vim code
authored
279 exec ":sbuffer " . error['bufnr']
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
280 call RedBar()
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
281 echo error_message
7e4384c @garybernhardt Added more ways to run tests in vim
authored
282 else
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
283 call GreenBar()
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
284 echo "All tests passed"
7e4384c @garybernhardt Added more ways to run tests in vim
authored
285 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
286 endfunction
e398051 @garybernhardt Made ,m run tests in Python files in vim
authored
287
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
288 function! RedBar()
289 hi RedBar ctermfg=white ctermbg=red guibg=red
290 echohl RedBar
291 echon repeat(" ",&columns - 1)
292 echohl
293 endfunction
294
295 function! GreenBar()
296 hi GreenBar ctermfg=white ctermbg=green guibg=green
297 echohl GreenBar
298 echon repeat(" ",&columns - 1)
299 echohl
300 endfunction
301
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
302 function! JumpToTestsForClass()
303 exec 'e ' . TestFileForCurrentClass()
304 endfunction
305
6828f02 @garybernhardt Made ,m run tests and jump to first error immediately in vim
authored
306 let mapleader=","
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
307 " nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
308 " nnoremap <leader>M :call RunTestsForFile('')<cr>
309 " nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
310 " nnoremap <leader>A :call RunAllTests('')<cr>
311
b7c24b5 @garybernhardt Vim test running hackery. Good luck to anyone trying to duplicate it now...
authored
312 " nnoremap <leader>a :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
313 " nnoremap <leader>A :call RunAllTests('')<cr>
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
314
d023313 @garybernhardt switch to vim-makegreen for test runs
authored
315 " nnoremap <leader>t :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
316 " nnoremap <leader>T :call RunAllTests('')<cr>
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
317
318 " nnoremap <leader>t :call JumpToTestsForClass()<cr>
8ae7a06 @garybernhardt Made vim use nose when doing :make
authored
319
4eb8860 @garybernhardt Enabled current line highlighting in vim
authored
320 " highlight current line
cb168a9 @garybernhardt Turned off cursorcolumn in vim
authored
321 set cursorline
3e4ba75 @garybernhardt Made the highlighted line in vim have a black background
authored
322
339b8fa @garybernhardt Set cmdheight to 2 in vim
authored
323 set cmdheight=2
324
75c2217 @garybernhardt Removed scroll bars in graphical vim
authored
325 " Don't show scroll bars in the GUI
326 set guioptions-=L
327 set guioptions-=r
328
84f9d65 @garybernhardt Switched from snippetsEmu to NERDSnippets
authored
329 " Use <c-h> for snippets
330 let g:NERDSnippets_key = '<c-h>'
331
3a7c566 @garybernhardt Set tabwidth to 2 for all Ruby code
authored
332 augroup myfiletypes
333 "clear old autocmds in group
334 autocmd!
335 "for ruby, autoindent with two spaces, always expand tabs
2f2d62b @garybernhardt switch cucumber to 2 space indent
authored
336 autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
d49b234 @garybernhardt Forced proper Python indenting in vim
authored
337 autocmd FileType python set sw=4 sts=4 et
3a7c566 @garybernhardt Set tabwidth to 2 for all Ruby code
authored
338 augroup END
339
7f7b1cd @garybernhardt Made vim use existing open splits when switching buffers (via switchbuf=...
authored
340 set switchbuf=useopen
341
db9463d @garybernhardt Fixed indentation of p and li tags in HTML in vim
authored
342 autocmd BufRead,BufNewFile *.html source ~/.vim/indent/html_grb.vim
343 autocmd FileType htmldjango source ~/.vim/indent/html_grb.vim
f5c33ea @garybernhardt add a bunch of new file types to vim
authored
344 autocmd! BufRead,BufNewFile *.sass setfiletype sass
db9463d @garybernhardt Fixed indentation of p and li tags in HTML in vim
authored
345
b031a98 @garybernhardt add <leader>v to view file in current directory
authored
346 " Map ,e and ,v to open files in the same directory as the current file
36ac100 @garybernhardt make ,e etc. expand current file path immediately
authored
347 cnoremap %% <C-R>=expand('%:h').'/'<cr>
348 map <leader>e :edit %%
349 map <leader>v :view %%
01837ca @garybernhardt add <leader>n to rename current file
authored
350 function! RenameFile()
351 let old_name = expand('%')
352 let new_name = input('New file name: ', expand('%'))
353 if new_name != '' && new_name != old_name
354 exec ':saveas ' . new_name
355 exec ':silent !rm ' . old_name
356 redraw!
357 endif
358 endfunction
359 map <leader>n :call RenameFile()<cr>
ac68b2a @garybernhardt Mapped ,e in vim to open files in the current directory
authored
360
23efff5 @garybernhardt Added ropevim
authored
361 if has("python")
362 source ~/.vim/ropevim/rope.vim
363 endif
3b9ca0c @garybernhardt Added cucumber syntax highlighting etc
authored
364
98c5076 @garybernhardt Added line numbers to vim
authored
365 set number
366 set numberwidth=5
367
9b1feab @garybernhardt Added Python complexity script invocation
authored
368 if has("gui_running")
ae26915 @garybernhardt Commented out complexity script in vim
authored
369 " source ~/proj/vim-complexity/repo/complexity.vim
9b1feab @garybernhardt Added Python complexity script invocation
authored
370 endif
371
dc14bb2 @garybernhardt Mapped :W to :w in vim. Because... seriously.
authored
372 " Seriously, guys. It's not like :W is bound to anything anyway.
373 command! W :w
374
3f2972c @garybernhardt Added some basic refactorings
authored
375 map <leader>rm :BikeExtract<cr>
376
377 function! ExtractVariable()
378 let name = input("Variable name: ")
379 if name == ''
380 return
381 endif
382 " Enter visual mode (not sure why this is needed since we're already in
383 " visual mode anyway)
384 normal! gv
385
386 " Replace selected text with the variable name
387 exec "normal c" . name
388 " Define the variable on the line above
389 exec "normal! O" . name . " = "
390 " Paste the original selected text to be the variable value
391 normal! $p
392 endfunction
393
394 function! InlineVariable()
395 " Copy the variable under the cursor into the 'a' register
396 " XXX: How do I copy into a variable so I don't pollute the registers?
397 :normal "ayiw
398 " It takes 4 diws to get the variable, equal sign, and surrounding
399 " whitespace. I'm not sure why. diw is different from dw in this respect.
400 :normal 4diw
401 " Delete the expression into the 'b' register
402 :normal "bd$
403 " Delete the remnants of the line
404 :normal dd
405 " Go to the end of the previous line so we can start our search for the
406 " usage of the variable to replace. Doing '0' instead of 'k$' doesn't
407 " work; I'm not sure why.
408 normal k$
409 " Find the next occurence of the variable
dd7ee73 @garybernhardt Made inline variable vim refactoring more precise
authored
410 exec '/\<' . @a . '\>'
3f2972c @garybernhardt Added some basic refactorings
authored
411 " Replace that occurence with the text we yanked
dd7ee73 @garybernhardt Made inline variable vim refactoring more precise
authored
412 exec ':.s/\<' . @a . '\>/' . @b
3f2972c @garybernhardt Added some basic refactorings
authored
413 endfunction
414
415 vnoremap <leader>rv :call ExtractVariable()<cr>
416 nnoremap <leader>ri :call InlineVariable()<cr>
7c57513 @garybernhardt comment out python navigation keystrokes
authored
417 " " Find comment
418 " map <leader>/# /^ *#<cr>
419 " " Find function
420 " map <leader>/f /^ *def\><cr>
421 " " Find class
422 " map <leader>/c /^ *class\><cr>
423 " " Find if
424 " map <leader>/i /^ *if\><cr>
425 " " Delete function
426 " " \%$ means 'end of file' in vim-regex-speak
427 " map <leader>df d/\(^ *def\>\)\\|\%$<cr>
428 " com! FindLastImport :execute'normal G<CR>' | :execute':normal ?^\(from\|import\)\><CR>'
429 " map <leader>/m :FindLastImport<cr>
3f2972c @garybernhardt Added some basic refactorings
authored
430
61bac18 @garybernhardt add fancier test running
authored
431 command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr>
3f2972c @garybernhardt Added some basic refactorings
authored
432
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
433 " Always show tab bar
434 set showtabline=2
482c82d @garybernhardt Added CommandT vim plugin
authored
435
64f4f74 @garybernhardt Added vim syntax for markdown
authored
436 augroup mkd
437 autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:&gt;
438 autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:&gt;
439 augroup END
440
f3ededf @garybernhardt Map ,y to copy to OS X pasteboard
authored
441 set makeprg=python\ -m\ nose.core\ --machine-out
442
6385839 @garybernhardt Simplify <leader>y pasteboard mapping (thanks, Yaniv Aknin!)
authored
443 map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
f3ededf @garybernhardt Map ,y to copy to OS X pasteboard
authored
444
4a0e096 @garybernhardt make <leader>' swap ' and " characters in vim
authored
445 " Make <leader>' switch between ' and "
446 nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>
447
bfb5bad @garybernhardt add keys to jump to specific rails files
authored
448 " Map keys to go to specific files
5d7adf2 @garybernhardt make routes and todos always be full width
authored
449 map <leader>gr :topleft :split config/routes.rb<cr>
5fee1eb @garybernhardt add <leader>gR to show routes in a split
authored
450 function! ShowRoutes()
451 " Requires 'scratch' plugin
5d7adf2 @garybernhardt make routes and todos always be full width
authored
452 :topleft 100 :split __Routes__
453 " Make sure Vim doesn't write __Routes__ as a file
454 :set buftype=nofile
455 " Delete everything
456 :normal 1GdG
457 " Put routes output in buffer
458 :0r! rake -s routes
459 " Size window to number of lines (1 plus rake output length)
460 :exec ":normal " . line("$") . "_ "
461 " Move cursor to bottom
462 :normal 1GG
463 " Delete empty trailing line
464 :normal dd
5fee1eb @garybernhardt add <leader>gR to show routes in a split
authored
465 endfunction
d4c21c1 @garybernhardt switch from Command-T to fuzzyfinder
authored
466 function! FindFile(prefix)
467 if a:prefix
468 :call fuf#setOneTimeVariables(['g:fuf_coveragefile_globPatterns', [a:prefix.'/**']])
469 endif
470 :FufCoverageFile
471 endfunction
5fee1eb @garybernhardt add <leader>gR to show routes in a split
authored
472 map <leader>gR :call ShowRoutes()<cr>
d4c21c1 @garybernhardt switch from Command-T to fuzzyfinder
authored
473 map <leader>gv :call FindFile('app/views')<cr>
474 map <leader>gc :call FindFile('app/controllers')<cr>
475 map <leader>gm :call FindFile('app/models')<cr>
476 map <leader>gh :call FindFile('app/helpers')<cr>
477 map <leader>gl :call FindFile('lib')<cr>
478 map <leader>gp :call FindFile('public')<cr>
479 map <leader>gs :call FindFile('public/stylesheets')<cr>
aa88f45 @garybernhardt add leader maps for Gemfile and integration specs
authored
480 map <leader>gg :topleft 100 :split Gemfile<cr>
d4c21c1 @garybernhardt switch from Command-T to fuzzyfinder
authored
481 map <leader>f :call FindFile('')<cr>
482 map <leader>gf :call FindFile('%%')<cr>
bfb5bad @garybernhardt add keys to jump to specific rails files
authored
483
bff2785 @garybernhardt remove OpenTestAlternate; using rails.vim now
authored
484 nnoremap <leader><leader> <c-^>
485
4fe5877 @garybernhardt add pathogen
authored
486 call pathogen#runtime_append_all_bundles()
487
61bac18 @garybernhardt add fancier test running
authored
488 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
489 " Running tests
490 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
491
492 " vim-makegreen binds itself to ,t unless something else is bound to its
493 " function.
494 map <leader>\dontstealmymapsmakegreen :w\|:call MakeGreen('spec')<cr>
495
496 function! RunTests(filename)
497 " Write the file and run tests for the given filename
498 :w
499 :silent !echo;echo;echo;echo;echo
c8b9b4d @garybernhardt make vim test running work without script/tests
authored
500 if filereadable("script/test")
501 exec ":!script/test " . a:filename
502 else
503 exec ":!bundle exec rspec " . a:filename
504 end
61bac18 @garybernhardt add fancier test running
authored
505 endfunction
506
507 function! SetTestFile()
508 " Set the spec file that tests will be run for.
d2ce5fd @garybernhardt improve test running behavior
authored
509 let t:grb_test_file=@%
61bac18 @garybernhardt add fancier test running
authored
510 endfunction
511
ce9b13f @garybernhardt run spec under cursor with <leader>T
authored
512 function! RunTestFile(...)
513 if a:0
514 let command_suffix = a:1
515 else
516 let command_suffix = ""
517 endif
518
61bac18 @garybernhardt add fancier test running
authored
519 " Run the tests for the previously-marked file.
6f99870 @garybernhardt tighten spec file matching
authored
520 let in_spec_file = match(expand("%"), '_spec.rb$') != -1
d2ce5fd @garybernhardt improve test running behavior
authored
521 if in_spec_file
522 call SetTestFile()
523 elseif !exists("t:grb_test_file")
524 return
525 end
ce9b13f @garybernhardt run spec under cursor with <leader>T
authored
526 call RunTests(t:grb_test_file . command_suffix)
527 endfunction
528
529 function! RunNearestTest()
530 let spec_line_number = line('.')
531 call RunTestFile(":" . spec_line_number)
61bac18 @garybernhardt add fancier test running
authored
532 endfunction
33a07ce @garybernhardt get command-t working again, finally
authored
533
61bac18 @garybernhardt add fancier test running
authored
534 map <leader>t :call RunTestFile()<cr>
ce9b13f @garybernhardt run spec under cursor with <leader>T
authored
535 map <leader>T :call RunNearestTest()<cr>
61bac18 @garybernhardt add fancier test running
authored
536 map <leader>a :call RunTests('spec')<cr>
c427c7b @garybernhardt add cucumber mappings
authored
537 map <leader>c :w\|:!cucumber<cr>
538 map <leader>C :w\|:!cucumber --profile wip<cr>
e74642f @garybernhardt add custom vim-makegreen maps
authored
539
072bc0e @garybernhardt add a bunch of crazy window management
authored
540 set winwidth=84
541 " We have to have a winheight bigger than we want to set winminheight. But if
542 " we set winheight to be huge before winminheight, the winminheight set will
543 " fail.
544 set winheight=5
545 set winminheight=5
546 set winheight=999
547
548 nnoremap <c-j> <c-w>j
549 nnoremap <c-k> <c-w>k
550 nnoremap <c-h> <c-w>h
551 nnoremap <c-l> <c-w>l
552 nnoremap <c-n> :let &wh = (&wh == 999 ? 10 : 999)<CR><C-W>=
80bed48 @garybernhardt add experimental tab stack keys
authored
553
09c5439 @garybernhardt switch to 256-color terminal and vim color scheme
authored
554 function! ShowColors()
555 let num = 255
556 while num >= 0
557 exec 'hi col_'.num.' ctermbg='.num.' ctermfg=white'
558 exec 'syn match col_'.num.' "ctermbg='.num.':...." containedIn=ALL'
559 call append(0, 'ctermbg='.num.':....')
560 let num = num - 1
561 endwhile
562 endfunction
563
6811403 @garybernhardt add :Md5 command to show MD5 of a range
authored
564 command! -range Md5 :echo system('echo '.shellescape(join(getline(<line1>, <line2>), '\n')) . '| md5')
565
3b5fd93 @garybernhardt imap <c-l> to hash rocket
authored
566 imap <c-l> <space>=><space>
567
86d12f2 @garybernhardt add command to open files with uncommitted changes
authored
568 function! OpenChangedFiles()
569 only " Close all windows, unless they're modified
570 let status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3')
571 let filenames = split(status, "\n")
572 exec "edit " . filenames[0]
573 for filename in filenames[1:]
574 exec "sp " . filename
575 endfor
576 endfunction
577 command! OpenChangedFiles :call OpenChangedFiles()
578
d94a113 @garybernhardt add keystrokes for diff mode
authored
579 if &diff
580 nmap <c-h> :diffget 1<cr>
581 nmap <c-l> :diffget 3<cr>
582 nmap <c-k> [cz.
583 nmap <c-j> ]cz.
584 set nonumber
585 endif
586
136c4c7 @garybernhardt add basic scroll-other-window keys
authored
587 " In these functions, we don't use the count argument, but the map referencing
588 " v:count seems to make it work. I don't know why.
589 function! ScrollOtherWindowDown(count)
590 normal! 
591 normal! 
592 normal! 
593 endfunction
594 function! ScrollOtherWindowUp(count)
595 normal! 
596 normal! 
597 normal! 
598 endfunction
599 nnoremap g<c-y> :call ScrollOtherWindowUp(v:count)<cr>
600 nnoremap g<c-e> :call ScrollOtherWindowDown(v:count)<cr>
601
8532a11 @garybernhardt sadly set shell to bash
authored
602 set shell=bash
603
Something went wrong with that request. Please try again.