2

I would like to tweak vim for using cdo (Climate Data Operators) efficiently. Because I need to use cdo in (bash) scripts, I would like to add an autocomplete matching (implemented!) with small description (still searching!).

I setup the environment and it works on a basic level. For now, I am wondering whether it's possible to manipulate the output of the pop-up menu on the right side of the matching dictionary keywords.

I got a simple keyword matching so far, see picture below:

Using the following setup:

My .vimrc: set completeopt=longest,menuone

Includes different dictionaries, mainly cdo.dic: ~/.vim/ftdetect/cdo.vim:

au BufRead,BufNewFile *.sh set dictionary+=~/.vim/dictionary/cdo.dic au BufRead,BufNewFile *.sh set dictionary+=~/.vim/dictionary/hamocc.dic au BufRead,BufNewFile *.sh set dictionary+=~/.vim/dictionary/mpiom.dic

My dictionary file ~/.vim/dictionary/cdo.dic: with is matched against

abs -abs \ adisit -adisit \ ...around 700 more....

Goal: What I would love to get as output is a small description that is displayed at the right, instead of the filepath of the dictionary file. So preferably a short explanation of the operator (which might be also stored in the dictionary file after the operator?), eg. for illustrative purpose

selcode : Select parameters by code number {selcode,code ifile ofile}

read from a dictionary line:

selcode -selcode {Select parameters by code number [selcode,code ifile ofile]}\

So basically, I quick lookup tool for operator names and short description without large programming, plugins with other external tools. So it's an 'Is it possible and how?' question...

I tried so far the vim documentation, and googling about vim, dictionary, complete, completeopt, pmenu, ...

I appreciate your suggestions.

0

You cannot influence the context information of dictionary completion (unless you directly change Vim's source code).

However, Vim provides the ability to implement custom completions. You'll find all relevant information and an example at :help complete-functions. With that, you have full control over the context (named menu, cp. :help complete-items).

You can stick with dictionary files as your source; you'd have to read in the file (e.g. via readfile()) and slightly parse it (matchlist()), or you directly define your dictionary items as a Vim List, in the Vim script implementing your custom completion.

  • Thanks, Ingo. I choose the second option with a VimList. However now I am stuck reading in data from a file. let l:data = [ \ ["selvar","selvar,varname","Select a variable"], \ ["sellonlatbox", "sellonlatbox,lon1,lon2,lat1,lat2","Select a longitude/latitude box"] \ ] but I dont get in loaded from a different file, eg. .vim/dictionary/cdo.dic with the same content as this hardcoded static entries. So basically I dont understand the readfile() command and how to use it – aaron.spring Sep 13 '16 at 22:18
  • so now it only works with for m in l:data if l:m[0] =~ '^' . a:base but not with something like for m in readfile("cdo_new.dic") – aaron.spring Sep 13 '16 at 22:26
  • now I managed to read in files via readline(), but I face the problem that all files are read in as vimL list items, so 'item1','item2' but I want to get item1,item2 because my items are lists like ["selvar","selvar,varname","description"] Is there any way to manipulate readfile in that way? – aaron.spring Sep 14 '16 at 20:27
  • I used the split function to read in items separately and then glued created a nested list out of those. Not pretty, I will see soon whether this also runs smooth with 1500 entries. – aaron.spring Sep 14 '16 at 23:25
  • works fine - done – aaron.spring Sep 16 '16 at 20:41
0

Finding this question led me to write a plugin:

https://github.com/jsit/vim-customcpt

It's built from the plugin that aaron.spring built in response to Ingo Karkat's accepted answer, but accepts any arbitrary json file as an autocomplete "dictionary".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.