在linux下终端或Vim中经常会发现不认识的单词, 然后ctrl+c然后到baidu里面来进行翻译, 就想找一种更简单的方法能快速翻译.sdcv全称为stardict console version, 即终端下的词典, 发现在网上查到的用户大都使用这个工具, 于是自己也想试一试.
我用的linux版本为manjaro
- 首先安装sdcv:
nication@develop:~# sudo pacman -S sdcv
- 安装词典数据, 之前只安装了不带数据的sdcv. 字典下载地址是:
https://pan.baidu.com/s/11hqBiGCqY2f1mdhsGhaj2wCode: 5pgg
根据需要选择合适的字典,嫌上边文件太大的可以:
http://download.huzheng.org/zh_CN/下载,建议下载langdao-ec-gb dictionary(en - zh_CN) 朗道英汉字典即可,43万多个单词,应该是足够了,
将压缩包解压到/usr/share/stardict/dic这个目录下(如果没有此目录则手工创建)
现在, 你在终端敲sdcv就可查询单词了.
nication@develop:/#sdcv face
save to cache /usr/share/stardict/dic/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.idx Found 1items, similar to face. -->朗道英汉字典5.0 -->face *[feis] n. 脸, 面容, 正面, 外观 vt. 面对, 朝, 正视, 面临 vi. 朝, 向 【计】 现场可改变的控制元件 【化】 端面 【医】 [颜]面, 面容 【经】 票面, 额面; 面对 相关词组: have the face to dosth accept the face of... face down face sth outface up to... fly inthe face of... hide one's face from... inthe face of... face to face with... face to face on the face of it save one's face put a newface on sth set one's face against... show one's face slap sb inthe face stare sb inthe face to sb's face criticize sb to his face hit sb in the face
但是我们还要在vim下使用查单词功能, 在vim的配置文件添加如下语句:
nication@develop:/# vim ~/.vimrc 在末尾添加:
set keywordprg=sdcv -u 朗道英汉字典5.0function!MySdcv() let retStr=system('sdcv '.expand("<cword>")) windo if expand("%")=="dictWin" |q!|endif 30vsp dictWin setlocal buftype=nofile bufhidden=hide noswapfile 1s/^/=retStr/ 1endfunction nnoremap F :call MySdcv()<CR>
其中
keywordprg的参数是由命令:sdcv -l的结果:Dictionary's name Word count
朗道英汉字典5.0 435468
此时在用vim打开的文件中, 在光标单词处, 按shift+f, 就可以查看单词了.结果如下:
我的终端设置的半透明,后面的是二进制壁纸,用的kde,开启了桌面特效。