├── .gitignore ├── plugin └── dict.vim ├── README.md └── doc └── dict.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /plugin/dict.vim: -------------------------------------------------------------------------------- 1 | " vim-dict - The Dict client for Vim 2 | " Maintainer: Szymon Wrozynski 3 | " Version: 1.2.1 4 | " 5 | " Installation: 6 | " Place in ~/.vim/plugin/dict.vim or in case of Pathogen: 7 | " 8 | " cd ~/.vim/bundle 9 | " git clone https://github.com/szw/vim-dict.git 10 | " 11 | " License: 12 | " Copyright (c) 2012 Szymon Wrozynski. Distributed under the same terms as Vim itself. 13 | " See :help license 14 | " 15 | " Usage: 16 | " https://github.com/szw/vim-dict/blob/master/README.md 17 | " 18 | 19 | if exists("g:loaded_dict") || &cp || v:version < 700 20 | finish 21 | endif 22 | 23 | let g:loaded_dict = 1 24 | 25 | if !exists("g:dict_curl_command") 26 | let g:dict_curl_command = "curl" 27 | endif 28 | 29 | if !exists("g:dict_curl_options") 30 | let g:dict_curl_options = "--connect-timeout 30" 31 | endif 32 | 33 | if !exists("g:dict_hosts") 34 | let g:dict_hosts = [["dict.org", ["all"]]] 35 | endif 36 | 37 | if !exists("g:dict_leave_pw") 38 | let g:dict_leave_pw = 0 39 | endif 40 | 41 | command! -nargs=? -range Dict :call s:dict() 42 | command! -nargs=0 DictShowDb :call s:dict_show_db() 43 | 44 | fun! s:dict(word) 45 | if (getpos('.') == getpos("'<")) && empty(a:word) 46 | let word = getline("'<")[getpos("'<")[2] - 1:getpos("'>")[2] - 1] 47 | else 48 | let word = empty(a:word) ? expand("") : a:word 49 | endif 50 | 51 | let word = substitute(tolower(word), '^\s*\(.\{-}\)\s*$', '\1', '') 52 | let quoted_word = "\"" . word . "\"" 53 | 54 | silent! | redraw | echo "Performing lookup for" quoted_word "- please wait..." 55 | 56 | silent! exe "noautocmd botright pedit Dict:'" . word . "'" 57 | noautocmd wincmd P 58 | setlocal modifiable 59 | setlocal buftype=nofile ff=dos 60 | setlocal nobuflisted 61 | 62 | for host in g:dict_hosts 63 | for db in host[1] 64 | silent! exe "noautocmd r!" g:dict_curl_command "-s" g:dict_curl_options "dict://" . host[0] . "/d:" . quoted_word . ":" . db 65 | endfor 66 | endfor 67 | 68 | silent! exe "%s/^151 //g" 69 | silent! exe "%s/^153 //g" 70 | silent! exe "%s/^\.$/--------------------------------------------------------------------------------/g" 71 | silent! exe "g/^[0-9][0-9][0-9]/d_" 72 | silent! exe "1d_" 73 | 74 | if line("$") == 1 75 | silent! exe "normal! a Nothing found for" quoted_word 76 | endif 77 | 78 | setlocal nomodifiable 79 | setlocal nofoldenable 80 | nnoremap q :bw! 81 | 82 | if g:dict_leave_pw 83 | noautocmd wincmd p 84 | endif 85 | endfun 86 | 87 | fun! s:dict_show_db() 88 | silent! | redraw | echo "Connecting to DICT servers - please wait..." 89 | 90 | silent! exe "noautocmd botright pedit Dict:show:db" 91 | noautocmd wincmd P 92 | setlocal modifiable 93 | set buftype=nofile ff=dos 94 | setlocal nobuflisted 95 | 96 | for host in g:dict_hosts 97 | silent! exe "normal! I--------------------------------------------------------------------------------\r" 98 | silent! exe "normal! IServer: " . host[0] . "\r" 99 | silent! exe "normal! I--------------------------------------------------------------------------------\r" 100 | silent! exe "noautocmd r!" g:dict_curl_command "-s" g:dict_curl_options "dict://" . host[0] . "/show:db" 101 | endfor 102 | 103 | silent! exe "%s/^110 //g" 104 | silent! exe "%s/^\.$//g" 105 | silent! exe "g/^\s*[0-9][0-9][0-9]/d_" 106 | silent! exe "g/^$/d_" 107 | silent! exe "0" 108 | 109 | setlocal nomodifiable 110 | setlocal nofoldenable 111 | nnoremap q :bw! 112 | 113 | if g:dict_leave_pw 114 | noautocmd wincmd p 115 | endif 116 | endfun 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-dict 2 | ======== 3 | 4 | **vim-dict** is a dict client. It uses **curl** to connect to dict servers, so make sure you have **curl** 5 | installed. 6 | 7 | 8 | Installation 9 | ------------ 10 | 11 | Place in *~/.vim/plugin/dict.vim* or in case of Pathogen: 12 | 13 | cd ~/.vim/bundle 14 | git clone https://github.com/szw/vim-dict.git 15 | 16 | Please, don't forget to star the repository if you like (and use) the plugin. This will let me know 17 | how many users it has and then how to proceed with further development :). 18 | 19 | Usage 20 | ----- 21 | 22 | To lookup a word (or words) in the dictionary use `Dict` command: 23 | 24 | :Dict hello 25 | :Dict start up 26 | 27 | The `Dict` command uses hosts and databases defined in the `g:dict_hosts` global list. By default it is set to 28 | `[["dict.org", ["all"]]]` (the format will be explained a bit later). 29 | 30 | `Dict` command can use a word under the cursor. Just move the cursor to a word and type in the command line: 31 | 32 | :Dict 33 | 34 | The same works on selection - just select multiple words in the Visual mode. 35 | 36 | The `:Dict` command will open a preview window. To close that window you may run `:pc`, or just hit 37 | `q` if the Dict window is the active one. 38 | 39 | 40 | Configuration 41 | ------------- 42 | 43 | There are just a few global variables (options) you may set in the *.vimrc* file. 44 | 45 | * `g:dict_hosts` 46 | 47 | The most important one is a list `g:dict_hosts` mentioned earlier. It combines hosts/databases used by 48 | **vim-dict**. The list entries are lists themselves and share the following format: 49 | 50 | ["host_name", ["database1", "database2", ...]] 51 | 52 | The sample extract from someone's *~/.vimrc* file could look like this: 53 | 54 | let g:dict_hosts = [ 55 | \["dict.org", ["all"]], 56 | \["dict.mova.org", ["slovnyk_en-pl", "slovnyk_pl-en"]] 57 | \] 58 | 59 | Moreover **vim-dict** can help you figure out what databases are available on your servers. There is 60 | a special command for this: 61 | 62 | :DictShowDb 63 | 64 | You can even open your *.vimrc* and provide some host urls only: 65 | 66 | let g:dict_hosts = [ 67 | \["dict.org", []], 68 | \["dict.mova.org", []] 69 | \] 70 | 71 | Then save and reload *.vimrc*, perform `DictShowDb` and yank-paste the databases you want :). 72 | 73 | The list of DICT servers can be found on the Internet, e.g. 74 | [here](http://luetzschena-stahmeln.de/dictd/index.php). 75 | 76 | If you have a local server with a dict deamon, you can use: 77 | 78 | let g:dict_hosts = [["localhost", ["*"]]] 79 | 80 | * `g:dict_leave_pw` 81 | 82 | If set to `1` **vim-dict** leaves the preview window (the focus remains on the current window). By default 83 | it is set to `0`. 84 | 85 | Example: 86 | 87 | let g:dict_leave_pw = 0 88 | 89 | * `g:dict_curl_command`[*][1] 90 | 91 | This variable holds the curl command to be fired by `Dict` function. You will find it handy if **curl** is 92 | not on your `$PATH` environment variable. By default it is set to `"curl"`. 93 | 94 | Example: 95 | 96 | let g:dict_curl_command = "curl" 97 | 98 | 99 | * `g:dict_curl_options`[*][1] 100 | 101 | Sometimes you might want to add additional options to the curl invocation, e.g. additonal proxy settings. 102 | By default it defines only the connection timeout. Notice, the option `-s` (silent) is always present 103 | regardless of this variable. 104 | 105 | Example: 106 | 107 | let g:dict_curl_options = "--connect-timeout 30" 108 | 109 | 110 | Useful tips 111 | ----------- 112 | 113 | On Ubuntu you might want to add system dictionary to Vim: 114 | 115 | set dictionary+=/usr/share/dict/words 116 | 117 | This will enable the dictionary in the insert mode (CTRL-X CTRL-K). Additionaly it could be useful to add the 118 | dictionary to the standard word completions (CTRL-N...) for text and Markdown file types. To do this set the 119 | `complete` to include *k* value: 120 | 121 | au FileType text,markdown setlocal complete+=k 122 | 123 | 124 | License 125 | ------- 126 | 127 | Copyright © 2012 Szymon Wrozynski. Distributed under the same terms as Vim itself. See `:help license` 128 | 129 | [1]: https://github.com/szw/vim-dict/pull/1 "Thanks to Ingo Karkat" 130 | -------------------------------------------------------------------------------- /doc/dict.txt: -------------------------------------------------------------------------------- 1 | *dict.txt* For Vim version 7.3 Last change: 2013-01-01 2 | *dict* 3 | 4 | 5 | 6 | 7 | 8 | 9 | Vim-Dict version 1.2.1~ 10 | 11 | The Dict client for Vim~ 12 | 13 | 14 | 15 | 16 | 17 | 18 | Copyright (c) 2012-2013 Szymon Wrozynski 19 | 20 | ============================================================================ 21 | Table of Contents 22 | 23 | 1. About......................................................|dict-about| 24 | 2. Usage......................................................|dict-usage| 25 | 3. Configuration......................................|dict-configuration| 26 | 4. Useful tips..........................................|dict-useful-tips| 27 | 5. Author and License................................|dict-author-license| 28 | 29 | ---------------------------------------------------------------------------- 30 | 1. About *dict-about* 31 | 32 | Vim-Dict is a dict client. It uses 'curl' to connect to dict servers, so make 33 | sure you have 'curl' installed. 34 | 35 | ---------------------------------------------------------------------------- 36 | 2. Usage *dict-usage* 37 | 38 | To lookup a word (or words) in the dictionary use 'Dict' command: > 39 | 40 | :Dict hello 41 | :Dict start up 42 | 43 | < 44 | 45 | The 'Dict' command uses hosts and databases defined in the |'dict_hosts'| 46 | global list. By default it is set to '[["dict.org", ["all"]]]' (the format 47 | will be explained a bit later). 48 | 49 | 'Dict' command can use a word under the cursor. Just move the cursor to a word 50 | and type in the command line: > 51 | 52 | :Dict 53 | 54 | < 55 | 56 | The same works on selection - just select multiple words in the Visual mode. 57 | 58 | The ':Dict' command will open a preview window. To close that window you may 59 | run ':pc', or just hit if the Dict window is the active one. 60 | 61 | ---------------------------------------------------------------------------- 62 | 3. Configuration *dict-configuration* 63 | 64 | There are just a few global variables (options) you may set in the '.vimrc' 65 | file. 66 | 67 | 68 | *'dict_hosts'* 69 | Default: '[["dict.org", ["all"]]]' 70 | 71 | The most important one is a list |'dict_hosts'| mentioned earlier. It combines 72 | hosts/databases used by Vim-Dict. The list entries are lists themselves and 73 | share the following format: > 74 | 75 | ["host_name", ["database1", "database2", ...]] 76 | 77 | < 78 | 79 | The sample extract from someone's '~/.vimrc' file could look like this: > 80 | 81 | let g:dict_hosts = [ 82 | \["dict.org", ["all"]], 83 | \["dict.mova.org", ["slovnyk_en-pl", "slovnyk_pl-en"]] 84 | \] 85 | < 86 | 87 | Moreover Vim-Dict can help you figure out what databases are available on your 88 | servers. There is a special command for this: > 89 | 90 | :DictShowDb 91 | 92 | < 93 | 94 | You can even open your '.vimrc' and provide some host urls only: > 95 | 96 | let g:dict_hosts = [ 97 | \["dict.org", []], 98 | \["dict.mova.org", []] 99 | \] 100 | 101 | < 102 | 103 | Then save and reload '.vimrc', perform 'DictShowDb' and yank-paste the 104 | databases you want :). 105 | 106 | The list of DICT servers can be found on the Internet, e.g. 107 | http://luetzschena-stahmeln.de/dictd/index.php. 108 | 109 | 110 | *'dict_leave_pw'* 111 | Default: 0 112 | 113 | If set to 1 Vim-Dict leaves the preview window (the focus remains on the 114 | current window). 115 | 116 | Example: > 117 | 118 | let g:dict_leave_pw = 0 119 | < 120 | 121 | 122 | *'dict_curl_command'* 123 | Default: 'curl' 124 | 125 | This variable holds the curl command to be fired by 'Dict' function. You will 126 | find it handy if 'curl' is not on your '$PATH' environment variable. 127 | 128 | Example: > 129 | 130 | let g:dict_curl_command = "curl" 131 | 132 | < 133 | 134 | 135 | *'dict_curl_options'* 136 | Default: '--connect-timeout 30' 137 | 138 | Sometimes you might want to add additional options to the curl invocation, 139 | e.g. additonal proxy settings. By default it defines only the connection 140 | timeout. Notice, the option '-s' (silent) is always present regardless of this 141 | variable. 142 | 143 | Example: > 144 | 145 | let g:dict_curl_options = "--connect-timeout 30" 146 | 147 | < 148 | 149 | 150 | ---------------------------------------------------------------------------- 151 | 4. Useful tips *dict-useful-tips* 152 | 153 | On Ubuntu you might want to add system dictionary to Vim: > 154 | 155 | set dictionary+=/usr/share/dict/words 156 | 157 | < 158 | 159 | This will enable the dictionary in the insert mode (). Additionaly 160 | it could be useful to add the dictionary to the standard word completions 161 | (...) for text and Markdown file types. To do this set the 'complete' to 162 | include 'k' value: > 163 | 164 | au FileType text,markdown setlocal complete+=k 165 | 166 | < 167 | 168 | ---------------------------------------------------------------------------- 169 | 5. Author and License *dict-author-license* 170 | 171 | Vim-Dict plugin was written by Szymon Wrozynski. It is licensed under the same 172 | terms as Vim itself. For more info see |license|. 173 | 174 | vim:tw=78:ts=4:ft=help:norl: 175 | --------------------------------------------------------------------------------