|" Searches Dash for the word under your cursor in vim, using the keyword|
|" configured to search j:term, which immediately brings up the JS doc|
|" for that keyword. Might need some customisation for your own keywords!|
|" 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:"|
|let s:searchType = ""|
|" Run it|
|let s:url = "dash://".s:searchType.s:wordUnderCursor|
|let s:cmd ="silent ! " . s:browser . " " . s:url|
|map <leader>d :call SearchDash()<CR>|
I'm running the new version of Dash (1.8.0) and using this. It works great, but this 'advanced' version searches for 'python:' when I'm in a Python file. This triggers a google/stackoverflow search, not a search for Python specific documentation.
I assumed (maybe incorrectly) that the intent was to search for the Python documentation specifically, not the Internet. Is this assumption incorrect, or am I doing something wrong?
Ah ha! I figure out what I was doing wrong with some help on Twitter from the developer. Just for reference if anyone runs into this I had python 2 and python 3 docsets installed. So my shortcuts for python were 'python2:' and 'python3' by default. Thus, 'python:' didn't match.
I just 'fixed' this by changing my search terms in dash to both map to 'python:'.
It's not ideal, but not sure the best way to detect this in the vim script unless you somehow detect what interpreter was referenced in the
I prefer having just this in my vimrc... you can expand it for any language you want. It knows the language based on the current filetype (:set ft?) rather than looking at the file's extension.
I usually end up with autocommands in my projects that will make 'filetype' look like qt5.cpp or rspec.rails.ruby, for finner control over snip engines and other things. I use Dash all the time, and thought this gists were really nice, so I put this together: