From 86c5fe1ea658892444e54ac7cb1a747e84754079 Mon Sep 17 00:00:00 2001 From: yan Date: Wed, 25 Apr 2012 19:39:31 -0700 Subject: [PATCH] Added `Ctrl-s` to open spec for any file you're looking at Similar to rails.vim's :A and :AV command, except it knows about fast_spec. Could be expanded in the future to add more spec paths. --- README.md | 2 ++ vim/plugin/settings/solarized.vim | 1 + vim/plugin/settings/yadr-keymap.vim | 8 +++--- vim/plugin/settings/yadr-spec-opener.vim | 32 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 vim/plugin/settings/yadr-spec-opener.vim diff --git a/README.md b/README.md index f0af9b6..120384b 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ files contain key mappings as well (TODO: probably will move them out to skwp-ke * `,qa/` - quickfix Ack last search (Steve Losh) * `,qg/` - quickfix GitGrep last search * `,T` - Tag list (list of methods in a class) + * `Ctrl-s` - Open related spec in a split. Similar to :A and :AV from rails.vim but is also aware of the fast_spec dir and faster to type #### File Navigation @@ -356,6 +357,7 @@ files contain key mappings as well (TODO: probably will move them out to skwp-ke * `,cf` - Copy Filename of current file (full path) into system (not vi) paste buffer * `,cn` - Copy Filename of current file (name only, no path) * `,vc` - (Vim Command) copies the command under your cursor and executes it in vim. Great for testing single line changes to vimrc. + * `,vr` - (Vim Reload) source current file as a vim file * `,yw` - yank a word from anywhere within the word (so you don't have to go to the beginning of it) * `,ow` - overwrite a word with whatever is in your yank buffer - you can be anywhere on the word. saves having to visually select it * `,w` - strip trailing whitespaces diff --git a/vim/plugin/settings/solarized.vim b/vim/plugin/settings/solarized.vim index de0695c..48ab2cd 100644 --- a/vim/plugin/settings/solarized.vim +++ b/vim/plugin/settings/solarized.vim @@ -14,6 +14,7 @@ hi! link rubyPseudoVariable Type hi! link rubyRailsARAssociationMethod Title hi! link rubyRailsARValidationMethod Title hi! link rubyRailsMethod Title +hi! link MatchParen DiffText " Enforce the colors set here au VimEnter * so ~/.vim/plugin/settings/solarized.vim diff --git a/vim/plugin/settings/yadr-keymap.vim b/vim/plugin/settings/yadr-keymap.vim index 019da5c..8f1ebfd 100644 --- a/vim/plugin/settings/yadr-keymap.vim +++ b/vim/plugin/settings/yadr-keymap.vim @@ -163,12 +163,12 @@ nnoremap ,cn :let @* = expand("%:t") "Clear current search highlight by double tapping // nmap // :nohlsearch -" (c)opy (c)ommand - which allows us to execute -" the line we're looking at (it does so by yy-copy, colon -" to get to the command mode, C-f to get to history editing -" p to paste it, C-c to return to command mode, and CR to execute +"(v)im (c)ommand - execute current line as a vim command nmap ,vc yy:p +"(v)im (r)eload +nmap ,vr :so % + " Type ,hl to toggle highlighting on/off, and show current value. noremap ,hl :set hlsearch! hlsearch? diff --git a/vim/plugin/settings/yadr-spec-opener.vim b/vim/plugin/settings/yadr-spec-opener.vim new file mode 100644 index 0000000..85c0855 --- /dev/null +++ b/vim/plugin/settings/yadr-spec-opener.vim @@ -0,0 +1,32 @@ +" Find the related spec for any file you open. Requires +" * Your specs live in spec/ or fast_spec/ +" * Your pwd (current dir) is the project root +" * You use the same dir structure in your code and specs so that +" code living at lib/foo/bar.rb has a spec at spec/lib/foo/bar.rb +" +" This method handles files in fast_spec unlike the :A and :AV functions +" that ship with rails.vim +function! FindSpec() + let s:fullpath = expand("%:p") + let s:filepath = expand("%:h") + let s:fname = expand("%:t") + + " Possible names for the spec/test for the file we're looking at + let s:test_names = [substitute(s:fname, ".rb$", "_spec.rb", ""), substitute(s:fname, ".rb$", "_test.rb", "")] + + " Possible paths + let s:test_paths = ["spec", "fast_spec", "test"] + for test_name in s:test_names + for path in s:test_paths + let s:filepath_without_app = substitute(s:filepath, "app/", "", "") + let s:spec_path = path . "/" . s:filepath_without_app . "/" . test_name + let s:full_spec_path = substitute(s:fullpath, s:filepath . "/" . s:fname, s:spec_path, "") + if filereadable(s:full_spec_path) + execute ":botright vsp " . s:full_spec_path + return + endif + endfor + endfor +endfunction + +nnoremap :call FindSpec()