"***************************************************************************** "** Name: transvim.vim - look up a word in a dictionary ** "** ** "** Type: global VIM plugin ** "** ** "** Author: Christian Habermann ** "** christian (at) habermann-net (point) de ** "** ** "** Copyright: (c) 2002 by Christian Habermann ** "** ** "** License: GNU General Public License 2 (GPL 2) or later ** "** ** "** This program is free software; you can redistribute it ** "** and/or modify it under the terms of the GNU General Public ** "** License as published by the Free Software Foundation; either ** "** version 2 of the License, or (at your option) any later ** "** version. ** "** ** "** This program is distributed in the hope that it will be ** "** useful, but WITHOUT ANY WARRANTY; without even the implied ** "** warrenty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ** "** PURPOSE. ** "** See the GNU General Public License for more details. ** "** ** "** Version: 1.0.2 ** "** tested under Linux and Win32, VIM and GVIM 6.2 ** "** ** "** History: 1.0.2 9. Oct. 2003 ** "** no new features, no bug-fixes, but corrections in comments ** "** - Comment-fix in Installation section: ** "** was: Unix: ~./vim/plugin ** "** now: Unix: ~/.vim/plugin ** "** - minor fixes in description ** "** ** "** 1.0.1 8. Dez. 2002 ** "** bug-fix: ** "** Removed mapping of to close view of results. In ** "** console version of VIM this mapping leaded to close view ** "** after pressing any cursor key - not only after . ** "** Now use 'q' instead of . ** "** Tested under Linux and Win32, VIM and GVIM 6.1. ** "** ** "** 1.0.0 28. Nov. 2002 ** "** same as 0.1.0, but first release ** "** ** "** 0.1.0 27. Nov. 2002: ** "** initial version, not released ** "** ** "** ** "***************************************************************************** "** Description: ** "** This script looks up a word/phrase in a dictionary. ** "** User can press key-shortcuts to translate word under cursor, visually ** "** selected text or to be asked for a word. ** "** ** "** Search-results are viewed in the same window in which searching was ** "** started. To close a view, press 'q' - TransVim will then switch ** "** back to the buffer comming from. ** "** ** "** There are several possibilities to start a translation: ** "** 1) move cursor over word to be translated and press tr ** "** 2) visually select word to be translated and press tr ** "** 3) press ta to be prompted for a word ** "** Memory aid: tr = (T)(R)anslate, ta = (T)ranslate (A)sk for word ** "** ** "** Note: by default is '\', so press \tr, \ta to start ** "** translation ** "** ** "** Keep in mind: when using a grep-like search program regular ** "** expressions can be used and must be taken into account when ** "** defining a search string. ** "** ** "** TransVim sets the phrase to be translated in quotes ("..."). You ** "** don't have to do it when looking for multi-word phrases (strictly ** "** speaking you are even not allowed to do it, unless you break them ** "** with a leading '\', see limitations below). ** "** ** "** In order to prevent tremendous huge search-results, the search- ** "** string must be at least 3 characters long (min. length is ** "** configurable). ** "** ** "** ** "** Installation: ** "** To use this script copy it into your local plugin-directory ** "** Unix: ~./.vim/plugin ** "** Windows: c:\vimfiles\plugin ** "** After starting VIM this script is sourced automatically. ** "** ** "** In .vimrc set path and filename of your dictionary, e.g. ** "** let g:trv_dictionary = "~/.vim/dictionary/ger-eng.txt" ** "** A dictionary is not included, see below for further information. ** "** By default "grep" is used for searching, so you need it too. It's ** "** available for close to all systems. Look for ports, if it is not ** "** installed already. ** "** ** "** ** "** Configuration: ** "** To configure TransVim you may set the following variables in your ** "** .vimrc-file. If they are not set, defaults will be taken. ** "** ** "** - TRV_TransVimVisual ** "** mapping to start translation of visually selected text ** "** default: ** "** vmap tr TRV_TransVimVisual ** "** ** "** - TRV_TransVimNormal ** "** mapping to start translation of word under cursor ** "** default: ** "** nmap tr TRV_TransVimNormal ** "** ** "** - TRV_TransVimAsk ** "** mapping to prompt for word to be translated ** "** default: ** "** map ta TRV_TransVimAsk ** "** ** "** - g:trv_dictionary ** "** path and filename of your dictionary ** "** default: ** "** let g:trv_dictionary = "~/.vim/dictionary/ger-eng.txt" ** "** ** "** - g:trv_grep ** "** name of grep used to search words in dictionary ** "** default: ** "** let g:trv_grep = "grep" ** "** ** "** - g:trv_grepOptions ** "** options for grep-command ** "** default: ** "** let g:trv_grepOptions = "-h -i" ** "** (print no filename, ignore case) ** "** ** "** - g:trv_minStrLen ** "** Minimal string length of the word to be translated. If word is ** "** shorter, translation will be canceled. ** "** default: ** "** let g:trv_minStrLen = 3 ** "** ** "** The grep-variables make it possible to replace the default grep by ** "** other search-programs without need of changing TransVim. For ** "** example use agrep instead of grep which provides approximate ** "** pattern search to find words which you don't exactly know how to ** "** spell. ** "** ** "** ** "** Dictionary: ** "** Must be a plain ASCII-text file where each line contains one ** "** word/phrase in language 1 and it's translation into language 2. ** "** TransVim lists all occurences of the searched word/phrase in this ** "** dictionary. ** "** A dictionary is not included but there is a plenty of free ** "** dictionaries available in the web. ** "** E.g.: ** "** - gerrman-english: ** "** dictionary from Ding-project (ger-eng.txt) ** "** Ding is (c) by Frank Richter, 1995-2002, License GPL 2 ** "** Online-version see http://dict.tu-chemnitz.de ** "** Comment: excellent database ** "** ** "** - others see http://www.linuks.mine.nu/dictionary/ ** "** They are done by Guerkan Senguen and released under GPL. ** "** Comment: quality unknown, I have not tested them ** "** ** "** ** "** Known limitations: ** "** - TransVim can't handle very well phrases containing double quotes. ** "** The only way it works is to enter the phrase manually in prompt- ** "** mode (ta) and set a '\' before each double quote. ** "** - Metacharacters of regular expressions introduced by a '\' ** "** (e.g. GNU grep's \(...\), \| ) will not work in visual mode. Do ** "** it in prompt-mode instead (ta). ** "** ** "** ** "** Known bugs: ** "** none - well, up to now :-) ** "** ** "** ** "** Happy vimming.... ** "***************************************************************************** " allow user to avoid loading this plugin and prevent loading twice if exists ("trv_transVimLoaded") finish endif let trv_transVimLoaded = 1 "***************************************************************************** "************************** C O N F I G U R A T I O N ************************ "***************************************************************************** " the mappings: if !hasmapto('TRV_TransVimVisual') vmap tr TRV_TransVimVisual endif if !hasmapto('TRV_TransVimNormal') nmap tr TRV_TransVimNormal endif if !hasmapto('TRV_TransVimAsk') map ta TRV_TransVimAsk endif vmap