Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 539 lines (444 sloc) 15.539 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
114 autocmd TabEnter,WinEnter,BufWinEnter *.rb match ErrorMsg '\%>78v.\+'
d9da825 @garybernhardt Initial commit
authored
115
116 " GRB: highlighting search"
117 set hls
118
119 if has("gui_running")
120 " GRB: set font"
121 ":set nomacatsui anti enc=utf-8 gfn=Monaco:h12
122
123 " GRB: set window size"
124 :set lines=100
d87898b @garybernhardt Widened vim window to make room for cyclomatic complexity annotations
authored
125 :set columns=171
d9da825 @garybernhardt Initial commit
authored
126
127 " GRB: highlight current line"
128 :set cursorline
129 endif
130
131 " GRB: set the color scheme
13e4d88 @garybernhardt Merged .gvimrc into .vimrc
authored
132 if has("gui_running")
133 :color grb3
134 else
0b2a0c5 @garybernhardt Switch to new grb4 vim color scheme
authored
135 :color grb4
d9da825 @garybernhardt Initial commit
authored
136 endif
137
13e4d88 @garybernhardt Merged .gvimrc into .vimrc
authored
138 " GRB: hide the toolbar in GUI mode
139 if has("gui_running")
140 set go-=T
141 end
142
d9da825 @garybernhardt Initial commit
authored
143 " GRB: add pydoc command
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
144 :command! -nargs=+ Pydoc :call ShowPydoc("<args>")
145 function! ShowPydoc(module, ...)
146 let fPath = "/tmp/pyHelp_" . a:module . ".pydoc"
147 :execute ":!pydoc " . a:module . " > " . fPath
148 :execute ":sp ".fPath
149 endfunction
d9da825 @garybernhardt Initial commit
authored
150
151 " GRB: Always source python.vim for Python files
152 au FileType python source ~/.vim/scripts/python.vim
153
154 " GRB: Use custom python.vim syntax file
155 au! Syntax python source ~/.vim/syntax/python.vim
156 let python_highlight_all = 1
157 let python_slow_sync = 1
158
159 " GRB: use emacs-style tab completion when selecting files, etc
160 set wildmode=longest,list
161
162 " GRB: Put useful info in status line
ea0b534 @garybernhardt simplify status line
authored
163 :set statusline=%<%f\ (%{&ft})%=%-19(%3l,%02c%03V%)
d9da825 @garybernhardt Initial commit
authored
164 :hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red
165
166 " GRB: clear the search buffer when hitting return
167 :nnoremap <CR> :nohlsearch<CR>/<BS>
168
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
169 " Remap the tab key to do autocompletion or indentation depending on the
170 " context (from http://www.vim.org/tips/tip.php?tip_id=102)
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
171 function! InsertTabWrapper()
172 let col = col('.') - 1
173 if !col || getline('.')[col - 1] !~ '\k'
174 return "\<tab>"
175 else
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
176 return "\<c-p>"
20b2475 @garybernhardt Removed trailing whitespace in .vimrc
authored
177 endif
178 endfunction
a6543a3 @garybernhardt Moved snippet completion to semicolon in vim
authored
179 inoremap <tab> <c-r>=InsertTabWrapper()<cr>
180 inoremap <s-tab> <c-n>
181
07d4301 @garybernhardt Added snipMate bound to the ; key in vim
authored
182 " When hitting <;>, complete a snippet if there is one; else, insert an actual
183 " <;>
184 function! InsertSnippetWrapper()
185 let inserted = TriggerSnippet()
186 if inserted == "\<tab>"
187 return ";"
188 else
189 return inserted
190 endif
191 endfunction
192 inoremap ; <c-r>=InsertSnippetWrapper()<cr>
193
d9da825 @garybernhardt Initial commit
authored
194 if version >= 700
195 autocmd FileType python set omnifunc=pythoncomplete#Complete
196 let Tlist_Ctags_Cmd='~/bin/ctags'
197 endif
198
7e4384c @garybernhardt Added more ways to run tests in vim
authored
199 function! RunTests(target, args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
200 silent ! echo
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
201 exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
b54f0e6 @garybernhardt Made test running from vim fancier
authored
202 silent w
62ff89d @garybernhardt Improved test behavior in MacVim
authored
203 exec "make " . a:target . " " . a:args
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
204 endfunction
205
206 function! ClassToFilename(class_name)
207 let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
208 let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
209 return file_name
210 endfunction
211
212 function! ModuleTestPath()
213 let file_path = @%
214 let components = split(file_path, '/')
215 let path_without_extension = substitute(file_path, '\.py$', '', '')
2c67ca3 @garybernhardt Removed old BitBacker-specific stuff in Python test running vim code
authored
216 let test_path = 'tests/unit/' . path_without_extension
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
217 return test_path
218 endfunction
219
220 function! NameOfCurrentClass()
221 let save_cursor = getpos(".")
222 normal $<cr>
223 call PythonDec('class', -1)
224 let line = getline('.')
225 call setpos('.', save_cursor)
226 let match_result = matchlist(line, ' *class \+\(\w\+\)')
227 let class_name = ClassToFilename(match_result[1])
228 return class_name
229 endfunction
230
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
231 function! TestFileForCurrentClass()
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
232 let class_name = NameOfCurrentClass()
233 let test_file_name = ModuleTestPath() . '/test_' . class_name . '.py'
234 return test_file_name
235 endfunction
236
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
237 function! TestModuleForCurrentFile()
238 let test_path = ModuleTestPath()
239 let test_module = substitute(test_path, '/', '.', 'g')
240 return test_module
241 endfunction
242
7e4384c @garybernhardt Added more ways to run tests in vim
authored
243 function! RunTestsForFile(args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
244 if @% =~ 'test_'
7e4384c @garybernhardt Added more ways to run tests in vim
authored
245 call RunTests('%', a:args)
5b95295 @garybernhardt Made ,m in vim run tests for class under cursor
authored
246 else
219dea6 @garybernhardt Made ,m run tests for current file instead of current class
authored
247 let test_file_name = TestModuleForCurrentFile()
7e4384c @garybernhardt Added more ways to run tests in vim
authored
248 call RunTests(test_file_name, a:args)
f03120a @garybernhardt Added proper handling of all tests passing in vim
authored
249 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
250 endfunction
251
7e4384c @garybernhardt Added more ways to run tests in vim
authored
252 function! RunAllTests(args)
b54f0e6 @garybernhardt Made test running from vim fancier
authored
253 silent ! echo
254 silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
255 silent w
b7c24b5 @garybernhardt Vim test running hackery. Good luck to anyone trying to duplicate it …
authored
256 exec "make!" . a:args
7e4384c @garybernhardt Added more ways to run tests in vim
authored
257 endfunction
258
259 function! JumpToError()
260 if getqflist() != []
c6bd76d @garybernhardt Added green and red bars when running tests in vim
authored
261 for error in getqflist()
262 if error['valid']
263 break
264 endif
265 endfor
266 let error_message = substitute(error['text'], '^ *', '', 'g')
9fb3a39 @garybernhardt Re-enabled jumping to the erroring line when running tests
authored
267 silent cc!
2c67ca3 @garybernhardt Removed old BitBacker-specific stuff in Python test running vim code
authored
268 exec ":sbuffer " . error['bufnr']
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
269 call RedBar()
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
270 echo error_message
7e4384c @garybernhardt Added more ways to run tests in vim
authored
271 else
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
272 call GreenBar()
61f3714 @garybernhardt Tweaked red/green test status bars in vim
authored
273 echo "All tests passed"
7e4384c @garybernhardt Added more ways to run tests in vim
authored
274 endif
b54f0e6 @garybernhardt Made test running from vim fancier
authored
275 endfunction
e398051 @garybernhardt Made ,m run tests in Python files in vim
authored
276
bfac1ba @garybernhardt Added better drawing of red/green bars in vim (from Bryan Ross)
authored
277 function! RedBar()
278 hi RedBar ctermfg=white ctermbg=red guibg=red
279 echohl RedBar
280 echon repeat(" ",&columns - 1)
281 echohl
282 endfunction
283
284 function! GreenBar()
285 hi GreenBar ctermfg=white ctermbg=green guibg=green
286 echohl GreenBar
287 echon repeat(" ",&columns - 1)
288 echohl
289 endfunction
290
4789e37 @garybernhardt Made ,t jump to the tests for the current class
authored
291 function! JumpToTestsForClass()
292 exec 'e ' . TestFileForCurrentClass()
293 endfunction
294
6828f02 @garybernhardt Made ,m run tests and jump to first error immediately in vim
authored
295 let mapleader=","
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
296 " nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
297 " nnoremap <leader>M :call RunTestsForFile('')<cr>
298 " nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
299 " nnoremap <leader>A :call RunAllTests('')<cr>
300
b7c24b5 @garybernhardt Vim test running hackery. Good luck to anyone trying to duplicate it …
authored
301 " nnoremap <leader>a :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
302 " nnoremap <leader>A :call RunAllTests('')<cr>
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
303
d023313 @garybernhardt switch to vim-makegreen for test runs
authored
304 " nnoremap <leader>t :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
305 " nnoremap <leader>T :call RunAllTests('')<cr>
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
306
307 " nnoremap <leader>t :call JumpToTestsForClass()<cr>
8ae7a06 @garybernhardt Made vim use nose when doing :make
authored
308
4eb8860 @garybernhardt Enabled current line highlighting in vim
authored
309 " highlight current line
cb168a9 @garybernhardt Turned off cursorcolumn in vim
authored
310 set cursorline
3e4ba75 @garybernhardt Made the highlighted line in vim have a black background
authored
311 hi CursorLine cterm=NONE ctermbg=black
312
339b8fa @garybernhardt Set cmdheight to 2 in vim
authored
313 set cmdheight=2
314
75c2217 @garybernhardt Removed scroll bars in graphical vim
authored
315 " Don't show scroll bars in the GUI
316 set guioptions-=L
317 set guioptions-=r
318
84f9d65 @garybernhardt Switched from snippetsEmu to NERDSnippets
authored
319 " Use <c-h> for snippets
320 let g:NERDSnippets_key = '<c-h>'
321
3a7c566 @garybernhardt Set tabwidth to 2 for all Ruby code
authored
322 augroup myfiletypes
323 "clear old autocmds in group
324 autocmd!
325 "for ruby, autoindent with two spaces, always expand tabs
f5c33ea @garybernhardt add a bunch of new file types to vim
authored
326 autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass set ai sw=2 sts=2 et
d49b234 @garybernhardt Forced proper Python indenting in vim
authored
327 autocmd FileType python set sw=4 sts=4 et
3a7c566 @garybernhardt Set tabwidth to 2 for all Ruby code
authored
328 augroup END
329
7f7b1cd @garybernhardt Made vim use existing open splits when switching buffers (via switchb…
authored
330 set switchbuf=useopen
331
db9463d @garybernhardt Fixed indentation of p and li tags in HTML in vim
authored
332 autocmd BufRead,BufNewFile *.html source ~/.vim/indent/html_grb.vim
333 autocmd FileType htmldjango source ~/.vim/indent/html_grb.vim
f5c33ea @garybernhardt add a bunch of new file types to vim
authored
334 autocmd! BufRead,BufNewFile *.sass setfiletype sass
db9463d @garybernhardt Fixed indentation of p and li tags in HTML in vim
authored
335
b031a98 @garybernhardt add <leader>v to view file in current directory
authored
336 " Map ,e and ,v to open files in the same directory as the current file
337 map <leader>e :edit <C-R>=expand("%:h")<cr>/
338 map <leader>v :view <C-R>=expand("%:h")<cr>/
ac68b2a @garybernhardt Mapped ,e in vim to open files in the current directory
authored
339
23efff5 @garybernhardt Added ropevim
authored
340 if has("python")
341 source ~/.vim/ropevim/rope.vim
342 endif
3b9ca0c @garybernhardt Added cucumber syntax highlighting etc
authored
343
344 autocmd BufRead,BufNewFile *.feature set sw=4 sts=4 et
3f05d38 @garybernhardt Added highlighting for long lines in vim
authored
345
98c5076 @garybernhardt Added line numbers to vim
authored
346 set number
347 set numberwidth=5
348
9b1feab @garybernhardt Added Python complexity script invocation
authored
349 if has("gui_running")
ae26915 @garybernhardt Commented out complexity script in vim
authored
350 " source ~/proj/vim-complexity/repo/complexity.vim
9b1feab @garybernhardt Added Python complexity script invocation
authored
351 endif
352
dc14bb2 @garybernhardt Mapped :W to :w in vim. Because... seriously.
authored
353 " Seriously, guys. It's not like :W is bound to anything anyway.
354 command! W :w
355
3f2972c @garybernhardt Added some basic refactorings
authored
356 map <leader>rm :BikeExtract<cr>
357
358 function! ExtractVariable()
359 let name = input("Variable name: ")
360 if name == ''
361 return
362 endif
363 " Enter visual mode (not sure why this is needed since we're already in
364 " visual mode anyway)
365 normal! gv
366
367 " Replace selected text with the variable name
368 exec "normal c" . name
369 " Define the variable on the line above
370 exec "normal! O" . name . " = "
371 " Paste the original selected text to be the variable value
372 normal! $p
373 endfunction
374
375 function! InlineVariable()
376 " Copy the variable under the cursor into the 'a' register
377 " XXX: How do I copy into a variable so I don't pollute the registers?
378 :normal "ayiw
379 " It takes 4 diws to get the variable, equal sign, and surrounding
380 " whitespace. I'm not sure why. diw is different from dw in this respect.
381 :normal 4diw
382 " Delete the expression into the 'b' register
383 :normal "bd$
384 " Delete the remnants of the line
385 :normal dd
386 " Go to the end of the previous line so we can start our search for the
387 " usage of the variable to replace. Doing '0' instead of 'k$' doesn't
388 " work; I'm not sure why.
389 normal k$
390 " Find the next occurence of the variable
dd7ee73 @garybernhardt Made inline variable vim refactoring more precise
authored
391 exec '/\<' . @a . '\>'
3f2972c @garybernhardt Added some basic refactorings
authored
392 " Replace that occurence with the text we yanked
dd7ee73 @garybernhardt Made inline variable vim refactoring more precise
authored
393 exec ':.s/\<' . @a . '\>/' . @b
3f2972c @garybernhardt Added some basic refactorings
authored
394 endfunction
395
396 vnoremap <leader>rv :call ExtractVariable()<cr>
397 nnoremap <leader>ri :call InlineVariable()<cr>
7c57513 @garybernhardt comment out python navigation keystrokes
authored
398 " " Find comment
399 " map <leader>/# /^ *#<cr>
400 " " Find function
401 " map <leader>/f /^ *def\><cr>
402 " " Find class
403 " map <leader>/c /^ *class\><cr>
404 " " Find if
405 " map <leader>/i /^ *if\><cr>
406 " " Delete function
407 " " \%$ means 'end of file' in vim-regex-speak
408 " map <leader>df d/\(^ *def\>\)\\|\%$<cr>
409 " com! FindLastImport :execute'normal G<CR>' | :execute':normal ?^\(from\|import\)\><CR>'
410 " map <leader>/m :FindLastImport<cr>
3f2972c @garybernhardt Added some basic refactorings
authored
411
61bac18 @garybernhardt add fancier test running
authored
412 command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr>
3f2972c @garybernhardt Added some basic refactorings
authored
413
ec18365 @garybernhardt change font, test running binds, and always show tab bar in vim
authored
414 " Always show tab bar
415 set showtabline=2
482c82d @garybernhardt Added CommandT vim plugin
authored
416
64f4f74 @garybernhardt Added vim syntax for markdown
authored
417 augroup mkd
418 autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:&gt;
419 autocmd BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:&gt;
420 augroup END
421
f3ededf @garybernhardt Map ,y to copy to OS X pasteboard
authored
422 set makeprg=python\ -m\ nose.core\ --machine-out
423
6385839 @garybernhardt Simplify <leader>y pasteboard mapping (thanks, Yaniv Aknin!)
authored
424 map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
f3ededf @garybernhardt Map ,y to copy to OS X pasteboard
authored
425
4a0e096 @garybernhardt make <leader>' swap ' and " characters in vim
authored
426 " Make <leader>' switch between ' and "
427 nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>
428
bfb5bad @garybernhardt add keys to jump to specific rails files
authored
429 " Map keys to go to specific files
5d7adf2 @garybernhardt make routes and todos always be full width
authored
430 map <leader>gr :topleft :split config/routes.rb<cr>
5fee1eb @garybernhardt add <leader>gR to show routes in a split
authored
431 function! ShowRoutes()
432 " Requires 'scratch' plugin
5d7adf2 @garybernhardt make routes and todos always be full width
authored
433 :topleft 100 :split __Routes__
434 " Make sure Vim doesn't write __Routes__ as a file
435 :set buftype=nofile
436 " Delete everything
437 :normal 1GdG
438 " Put routes output in buffer
439 :0r! rake -s routes
440 " Size window to number of lines (1 plus rake output length)
441 :exec ":normal " . line("$") . "_ "
442 " Move cursor to bottom
443 :normal 1GG
444 " Delete empty trailing line
445 :normal dd
5fee1eb @garybernhardt add <leader>gR to show routes in a split
authored
446 endfunction
447 map <leader>gR :call ShowRoutes()<cr>
5d7adf2 @garybernhardt make routes and todos always be full width
authored
448 map <leader>gd :topleft 100 :split spec/todo_spec.rb<cr>
a885059 @garybernhardt add keystrokes to edit different types of files
authored
449 map <leader>gv :CommandTFlush<cr>\|:CommandT app/views<cr>
450 map <leader>gV :CommandTFlush<cr>\|:CommandT spec/views<cr>
451 map <leader>gc :CommandTFlush<cr>\|:CommandT app/controllers<cr>
452 map <leader>gC :CommandTFlush<cr>\|:CommandT spec/controllers<cr>
453 map <leader>gm :CommandTFlush<cr>\|:CommandT app/models<cr>
454 map <leader>gM :CommandTFlush<cr>\|:CommandT spec/models<cr>
2daaa84 @garybernhardt switch <leader>gl to open lib instead of layouts
authored
455 map <leader>gl :CommandTFlush<cr>\|:CommandT lib<cr>
a885059 @garybernhardt add keystrokes to edit different types of files
authored
456 map <leader>gs :CommandTFlush<cr>\|:CommandT public/stylesheets<cr>
9b9e0f3 @garybernhardt add a keystroke to switch between test and prod code
authored
457 function! OpenTestAlternate()
4016ae9 @garybernhardt extract method in vimrc
authored
458 let new_file = AlternateForCurrentFile()
459 exec ':e ' . new_file
460 endfunction
461 function! AlternateForCurrentFile()
9b9e0f3 @garybernhardt add a keystroke to switch between test and prod code
authored
462 let current_file = expand("%")
355af13 @garybernhardt make spec/prod switching work with lib
authored
463 let new_file = current_file
464 let in_spec = match(current_file, '^spec/') != -1
465 let going_to_spec = !in_spec
466 let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1
467 if going_to_spec
468 if in_app
469 let new_file = substitute(new_file, '^app/', '', '')
470 end
471 let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
472 let new_file = 'spec/' . new_file
9b9e0f3 @garybernhardt add a keystroke to switch between test and prod code
authored
473 else
355af13 @garybernhardt make spec/prod switching work with lib
authored
474 let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
475 let new_file = substitute(new_file, '^spec/', '', '')
476 if in_app
477 let new_file = 'app/' . new_file
478 end
9b9e0f3 @garybernhardt add a keystroke to switch between test and prod code
authored
479 endif
4016ae9 @garybernhardt extract method in vimrc
authored
480 return new_file
9b9e0f3 @garybernhardt add a keystroke to switch between test and prod code
authored
481 endfunction
d7c461e @garybernhardt switch open-test-alternate key
authored
482 nnoremap <leader><leader> :call OpenTestAlternate()<cr>
bfb5bad @garybernhardt add keys to jump to specific rails files
authored
483
4fe5877 @garybernhardt add pathogen
authored
484 call pathogen#runtime_append_all_bundles()
485
61bac18 @garybernhardt add fancier test running
authored
486 function! SetGRBRailsCompiler()
d023313 @garybernhardt switch to vim-makegreen for test runs
authored
487 compiler grbrails
488 hi GreenBar term=reverse ctermfg=black ctermbg=green guifg=white guibg=green
489 endfunction
490 autocmd BufNewFile,BufRead *.rb call SetGRBRailsCompiler()
491 map <leader>T :make<cr>
492
33a07ce @garybernhardt get command-t working again, finally
authored
493 let g:CommandTCursorStartMap='<leader>f'
61bac18 @garybernhardt add fancier test running
authored
494 map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
495
496 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
497 " Running tests
498 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
499
500 " vim-makegreen binds itself to ,t unless something else is bound to its
501 " function.
502 map <leader>\dontstealmymapsmakegreen :w\|:call MakeGreen('spec')<cr>
503
504 function! RunTests(filename)
505 " Write the file and run tests for the given filename
506 :w
507 :silent !echo;echo;echo;echo;echo
508 exec ":!script/tests " . a:filename
509 endfunction
510
511 function! SetTestFile()
512 " Set the spec file that tests will be run for.
d2ce5fd @garybernhardt improve test running behavior
authored
513 let t:grb_test_file=@%
61bac18 @garybernhardt add fancier test running
authored
514 endfunction
515
516 function! RunTestFile()
517 " Run the tests for the previously-marked file.
6f99870 @garybernhardt tighten spec file matching
authored
518 let in_spec_file = match(expand("%"), '_spec.rb$') != -1
d2ce5fd @garybernhardt improve test running behavior
authored
519 if in_spec_file
520 call SetTestFile()
521 elseif !exists("t:grb_test_file")
522 return
523 end
524 call RunTests(t:grb_test_file)
61bac18 @garybernhardt add fancier test running
authored
525 endfunction
33a07ce @garybernhardt get command-t working again, finally
authored
526
61bac18 @garybernhardt add fancier test running
authored
527 map <leader>t :call RunTestFile()<cr>
528 map <leader>a :call RunTests('spec')<cr>
e74642f @garybernhardt add custom vim-makegreen maps
authored
529
80bed48 @garybernhardt add experimental tab stack keys
authored
530 " Tab stack
531 for i in range(1, 9)
532 exec "map " . i . " :tabnext " . i . "<cr>"
533 endfor
534 map <c-k> :tablast\|:tabnew<cr>
535 map <c-j> :tabclose<cr>
536 map <c-h> :tabprevious<cr>
537 map <c-l> :tabnext<cr>
538
Something went wrong with that request. Please try again.