Skip to content

Instantly share code, notes, and snippets.

@wangshijun
Forked from yjsoon/gist:3485271
Created March 14, 2013 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangshijun/5159874 to your computer and use it in GitHub Desktop.
Save wangshijun/5159874 to your computer and use it in GitHub Desktop.
" Searches Dash for the word under your cursor in vim, using the keyword
" operator, based on file type. E.g. for JavaScript files, I have it
" configured to search j:term, which immediately brings up the JS doc
" for that keyword. Might need some customisation for your own keywords!
function! SearchDash()
" Some setup
let s:browser = "/usr/bin/open"
let s:wordUnderCursor = expand("<cword>")
" Get the filetype (everything after the first ., for special cases
" such as index.html.haml or abc.css.scss.erb)
let s:fileType = substitute(expand("%"),"^[^.]*\.","",1)
" Alternative ways of getting filetype, aborted
" let s:fileType = expand("%:e")
" let s:searchType = b:current_syntax.":"
" Match it and set the searchType -- make sure these are the right shortcuts
" in Dash! Sort by priority in the match list below if necessary, because
" Tilt-enabled projects may have endings like .scss.erb.
if match(s:fileType, "js") != -1
let s:searchType = "js:" " can assign this to jQuery, too
elseif match(s:fileType, "css") != -1
let s:searchType = "css:"
elseif match(s:fileType, "html") != -1
let s:searchType = "html:"
elseif match(s:fileType, "rb") != -1
let s:searchType = "rb:" " can assign this to Rails, too
elseif match(s:fileType, "php") != -1
let s:searchType = "php:"
elseif match(s:fileType, "py") != -1
let s:searchType = "python:"
else
let s:searchType = ""
endif
" Run it
let s:url = "dash://".s:searchType.s:wordUnderCursor
let s:cmd ="silent ! " . s:browser . " " . s:url
execute s:cmd
redraw!
endfunction
map <leader>d :call SearchDash()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment