Skip to content

Instantly share code, notes, and snippets.

@deris
Created July 4, 2013 17:30

Revisions

  1. deris created this gist Jul 4, 2013.
    23 changes: 23 additions & 0 deletions open_neobundlepath1.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    NeoBundle 'tyru/open-browser'

    nnoremap gz vi':<C-u>call ExecuteWithSelectedText('OpenBrowser https://github.com/%s')<CR>
    vnoremap gz :<C-u>call ExecuteWithSelectedText('OpenBrowser https://github.com/%s')<CR>
    " visualモードで最後に選択したテキストを%sで指定してコマンドを実行する {{{
    function! ExecuteWithSelectedText(command)
    if a:command !~? '%s'
    return
    endif

    let reg = '"'
    let [save_reg, save_type] = [getreg(reg), getregtype(reg)]
    normal! gvy
    let selectedText = @"
    call setreg(reg, save_reg, save_type)
    if selectedText == ''
    return
    endif

    execute printf(a:command, selectedText)
    endfunction
    " }}}