├── LICENSE ├── README.md ├── doc └── vim-search-web.txt └── plugin └── vim-search-web.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Rajasegar Chandran 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-search-web 2 | 3 | Search the web from your Vim editor 4 | 5 | ## Install 6 | 7 | Place in `~/.vim/plugin/vim-search-web.vim` 8 | 9 | ### For Pathogen 10 | 11 | ```sh 12 | cd ~/.vim/bundle 13 | git clone https://github.com/rajasegar/vim-search-web.git 14 | ``` 15 | 16 | ### With Vundle 17 | Add this to your plugins list in `.vimrc` 18 | 19 | ```sh 20 | Plugin 'rajasegar/vim-search-web' 21 | ``` 22 | 23 | 24 | ## Usage 25 | 26 | ### Normal mode 27 | Just place the cursor on any word about which you want to search and use 28 | the key binding `sg`. 29 | 30 | That's all, now a separate browser window will open with your search results. 31 | 32 | ### Visual mode 33 | Just select any word about which you want to search and use 34 | the key binding `sg`. 35 | 36 | ### Ex mode 37 | 38 | You can specify the supported search engines as the first parameter and 39 | then followed by the keyword. 40 | 41 | ```sh 42 | :OpenSearch("Google", "hello world") 43 | ``` 44 | 45 | ## Key Bindings 46 | - [Leader]sdi => Dictionary Search 47 | - [Leader]sd => DuckduckGo Search 48 | - [Leader]sgi => Github Search 49 | - [Leader]sg => Google Search 50 | - [Leader]sn => npm Search 51 | - [Leader]sr => reddit Search 52 | - [Leader]ss => StackOverflow Search 53 | - [Leader]st => Thesaurus Search 54 | - [Leader]sw => Wikipedia Search 55 | - [Leader]sy => Youtube Search 56 | 57 | 58 | ## Configuration 59 | 60 | There are just a few global variables (options) you may set in the *.vimrc* file. 61 | 62 | * `g:vsw_open_command` 63 | 64 | Sets the command used to open the URL. In case of Ubuntu this would be 65 | `"xdg-open"`: 66 | 67 | let g:vsw_open_command = "xdg-open" 68 | 69 | 70 | ## FAQS 71 | 72 | ### Not able to search keywords with '-' (hyphens) 73 | This plugin is using `CWORD` so spaces and other special characters like hyphens are ignored. 74 | So if you want to include hypens also in your search keywords, just add them(temporarily) to `iskeyword`. 75 | 76 | ```sh 77 | :set iskeyword+=- 78 | ``` 79 | 80 | ## Other Similar plugins 81 | - https://github.com/szw/vim-g 82 | - https://github.com/mickaobrien/vim-stackoverflow 83 | - [vim-search-me](https://github.com/rajasegar/vim-search-web) 84 | -------------------------------------------------------------------------------- /doc/vim-search-web.txt: -------------------------------------------------------------------------------- 1 | *vim-search-web.txt* A Vim plugin to search the web 2 | 3 | Author: Rajasegar Chandran 4 | License: Same terms as Vim itself (see |license|) 5 | 6 | This plugin is only available if 'compatible' is not set. 7 | 8 | INTRODUCTION *vim-search-web* 9 | 10 | Developers often want to lookup something from their source code. 11 | And the search is not simply through Google, so this plugin helps 12 | you to search about a keyword from multiple sources like Stack Overflow, 13 | Github, npm, etc., 14 | 15 | COMMANDS *vim-search-web-commands* 16 | 17 | These commands are local to the buffers in which they work (generally, buffers 18 | that are part of Git repositories). 19 | 20 | *vim-search-web-:OpenSearch* 21 | :OpenSearch [args] Search using Google OpenSearch("Google", "hello") 22 | 23 | 24 | MAPPINGS *vim-search-web-mappings* 25 | 26 | 27 | *vim-search-web-global-mappings* 28 | Global mappings ~ 29 | 30 | *vim-search-web_LEADER_sd 31 | sd DuckDuckGo Search 32 | 33 | *vim-search-web_LEADER_sdi 34 | 35 | sdi Learner's Dictionary Search 36 | 37 | *vim-search-web_LEADER_sg 38 | sg Google Search 39 | 40 | *vim-search-web_LEADER_sgi 41 | sgi Github Search 42 | 43 | *vim-search-web_LEADER_ss 44 | ss StackOverflow Search 45 | 46 | *vim-search-web_LEADER_sn 47 | sn npm Search 48 | 49 | *vim-search-web_LEADER_sw 50 | sw Wikipedia Search 51 | 52 | *vim-search-web_LEADER_sr 53 | sr Reddit Search 54 | 55 | *vim-search-web_LEADER_st 56 | st Thesaurus Search 57 | 58 | *vim-search-web_LEADER_sy 59 | sy Youtube Search 60 | 61 | ABOUT *vim-search-web-about* 62 | 63 | Grab the latest version or report a bug on GitHub: 64 | 65 | http://github.com/rajasegar/vim-search-web 66 | 67 | vim:tw=78:et:ft=help:norl: 68 | -------------------------------------------------------------------------------- /plugin/vim-search-web.vim: -------------------------------------------------------------------------------- 1 | " vim-search-web.vim - Search keywords in vim from various sources 2 | " Maintainer: Rajasegar Chandran 3 | " Version: 0.0.4 4 | 5 | 6 | " add new engines here to automatically generate a command and a keymap 7 | " :Open{Engine}Search 8 | " s{FirstLetterOfEngine} 9 | let s:engines = { 10 | \ 'Duckduckgo': 'https://duckduckgo.com/?q=', 11 | \ "Google": 'https://google.com/search?q=', 12 | \ "Github": 'https://github.com/search?q=', 13 | \ "Stackoverflow": 'https://stackoverflow.com/search?q=', 14 | \ "Npm": 'https://npmjs.com/search?q=', 15 | \ "Wikipedia": 'http://wikipedia.com/w/', 16 | \ "Reddit": 'https://www.reddit.com/search/?q=', 17 | \ "Thesaurus": 'https://www.thesaurus.com/browse/', 18 | \ "Dictionary": 'http://www.learnersdictionary.com/definition/', 19 | \ "Youtube": 'https://www.youtube.com/results?search_query=', 20 | \ } 21 | 22 | 23 | " Mappings 24 | " single letter mappings - automatic, dont touch 25 | for engine in keys(s:engines) 26 | execute "nnoremap s".tolower(engine[0:0])." :call OpenSearch('".engine."',expand('')) " 27 | execute "vnoremap s".tolower(engine[0:0])." :call OpenSearch('".engine."',GetVisualSelection()) " 28 | endfor 29 | " double letter mappings (for 2 searches that start with the same letter) 30 | nnoremap sgi :call OpenSearch("Github",expand('')) 31 | nnoremap sdi :call OpenSearch("Dictionary",expand('')) 32 | vnoremap sgi :call OpenSearch("Github",GetVisualSelection()) 33 | vnoremap sdi :call OpenSearch("Dictionary",GetVisualSelection()) 34 | 35 | if exists("g:loaded_vim_search_web") || &cp || v:version < 700 36 | finish 37 | endif 38 | 39 | let g:loaded_vim_search_web = 1 40 | 41 | " Taken from szw/vim-g 42 | " to support other platforms like Linux and Windows 43 | if !exists("g:vsw_open_command") 44 | if has("win32") 45 | let g:vsw_open_command = "start" 46 | elseif substitute(system('uname'), "\n", "", "") == 'Darwin' 47 | let g:vsw_open_command = "open" 48 | else 49 | let g:vsw_open_command = "xdg-open" 50 | endif 51 | endif 52 | 53 | 54 | " Functions 55 | function! OpenSearch(engine, keyword) 56 | if has_key(s:engines, a:engine) 57 | let url = s:engines[a:engine] . a:keyword 58 | exec '!'.g:vsw_open_command.' "'.url.'"' 59 | endif 60 | endfunction 61 | 62 | " this is from stackoverflow. i dont know why it works, but it does 63 | function! GetVisualSelection() 64 | " Why is this not a built-in Vim script function?! 65 | let [line_start, column_start] = getpos("'<")[1:2] 66 | let [line_end, column_end] = getpos("'>")[1:2] 67 | let lines = getline(line_start, line_end) 68 | if len(lines) == 0 69 | return '' 70 | endif 71 | let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] 72 | let lines[0] = lines[0][column_start - 1:] 73 | return join(lines, "\n") 74 | endfunction 75 | 76 | " Commands 77 | for engine in keys(s:engines) 78 | execute "command! -nargs=1 Open".engine."Search call OpenSearch('".engine."',)" 79 | endfor 80 | --------------------------------------------------------------------------------