Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Last active December 14, 2015 00:49
Show Gist options
  • Save lucascaton/5001446 to your computer and use it in GitHub Desktop.
Save lucascaton/5001446 to your computer and use it in GitHub Desktop.
Add this code to your ~/.vimrc.
" RSpec focus
function! s:Preserve(command)
" Save cursor position
let l = line(".")
let c = col(".")
" Do the business
execute a:command
" Restore cursor position
call cursor(l, c)
" Remove search history pollution and restore last search
call histdel("search", -1)
let @/ = histget("search", -1)
endfunction
function! s:AddFocusTag()
call s:Preserve("normal! ^ / do\<cr>C, focus: true do\<esc>")
endfunction
function! s:RemoveAllFocusTags()
call s:Preserve("%s/, focus: true//e")
endfunction
command! -nargs=0 AddFocusTag call s:AddFocusTag()
command! -nargs=0 RemoveAllFocusTags call s:RemoveAllFocusTags()
:nnoremap <leader>t :AddFocusTag<CR>
:nnoremap <leader>r :RemoveAllFocusTags<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment