Install and use SDCV and improve the experience of SDCV under VIM

Source: Internet
Author: User
Tags bz2 epel repo



Note: A direct look at the last chapter of the improved VIM experience


first, what is SDCV


The terminal dictionary SDCV, as its name implies, is the dictionary tool used under the terminal.



I understand what it says about the terminal: wherever it can be used, it can be the shell itself, or it can be inside a software.


Second, why choose it


1. As a tool, he is not bound to dictionaries, easy to replace and multi-dictionary simultaneous query.



2. Does not rely on the GUI, the versatility is strong, the stability is strong.



3. With a variety of software can invoke the shell command, easy to use.


third, SDCV installation


Install SDCV with installation commands, and most repositories have



Examples are as follows:

CentOS, RHEL, Fedora (need EPEL repo)
$ yum install sdcv
Ubuntu, Deban
$ sudo apt-get install sdcv
Attach sdcv in case you need to install it by yourself

http://dushistov.github.io/sdcv/

4. Dictionary installation 1. Download the dictionary
Available dictionaries: http://download.huzheng.org/

$ cd / tmp
Landau English-Chinese Dictionary
$ wget http://download.huzheng.org/zh_CN/stardict-langdao-ec-gb-2.4.2.tar.bz2
Landau Chinese-English Dictionary
$ wget http://download.huzheng.org/zh_CN/stardict-langdao-ce-gb-2.4.2.tar.bz2
2. Install the dictionary
Extract the dictionary to the ~ / .stardict / dic directory

$ mkdir -p ~ / .stardict / dic
$ cd ~ / .stardict / dic
$ tar xvf /tmp/stardict-langdao-ec-gb-2.4.2.tar.bz2
$ tar xvf /tmp/stardict-langdao-ce-gb-2.4.2.tar.bz2
Five, basic use
Command for single query: sdcv hello

Continuous query using command: sdcv enter, then query, query, query, ctrl + c exit after query

Query the installed dictionary using command: sdcv -l

Six, vim transformation (thesis) 1. Transformation goals and ideas
Can use a shortcut key in vim to make vim pop up a window to display the translation of the current cursor

Because programming often has multiple words connected together, it is best to use: command + word to produce the same effect.

Then we have to write a user function, and then use key mapping and user commands to achieve the goal.

2. Specific methods
Add the following code to ~ / .vim / plugin / sdcv.vim file

 1 function! My_sdcv (word)
 2 let expl = system (‘sdcv -n‘.
 3 \ expand (a: word == "that word"? "<Cword>": a: word))
 4 windo if
 5 \ expand ("%") == "diCt-tmp" | q! | Endif
 6 vsplit diCt-tmp
 7 setlocal buftype = nofile bufhidden = hide noswapfile
 8 1s / ^ / \ = expl /
 9 1
10 exe "normal \ <c-W> L"
11 vertical res 25
12 exe "normal \ <c-W> p"
13 endfunction
Add the following code to the ~ / .vimrc file

1 nmap K: call My_sdcv ("that word") <CR>
2 command -nargs = 1 FY call My_sdcv ("<args>")
The K in the first row can be changed to any unused shortcut key or combination

FY in the second line can be changed to any unused command name that starts with a capital letter

3. Use
Open vim, use input K in normal mode, you can observe a window of 25 columns on the right, showing the translation of the word under the cursor

FY Hello has the same effect in command mode

 

Install and use sdcv and improve the experience of using sdcv under vim

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.