Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I create a custom completion pop up menu.

I would like to be able to begin typing a part of a string then press a custom key combination to bring up a pop up completion of just a certain group of strings.

I already have omni complete set up and do not want to add to that list.

For example I have the list:
spo
spe
spa

I would like to be able to type sp then press ctrl+> and have a completion box come up for just that specific list.

share|improve this question
add comment

2 Answers

Create a list of words: $HOME/wordlist and add the dictionary to vim.

:set dictionary+=$HOME/wordlist

Activate the word list:

:set complete-=k complete+=k

Now you can autocomplete the words with <CTRL>-P and <CTRL-N

Edit: To have separate word lists, you create multiple lists, e.g.

$HOME/firstlist
$HOME/secondlist

and assign key bindings to pick a particular work list:

noremap <F5> :set dictionary=$HOME/firstlist<CR>:set complete-=k complete+=k<CR>
noremap <F6> :set dictionary=$HOME/secondlist<CR>:set complete-=k complete+=k<CR>

This has the advantage that you can use the <CTRL>-P and <CTRL>-N shortcuts as you're used to, once you picked the desired list.

share|improve this answer
    
Can I have separate dictionaries though? I would like a hot key for only a specific list. I am already using a dictionary. –  James Andino May 22 '12 at 3:02
    
@JamesAndino I updated my answer. –  Marco May 22 '12 at 10:34
add comment
up vote 2 down vote accepted
  inoremap <F5> <C-R>=ListMonths()<CR>

    func! ListMonths()
      call complete(col('.'), ['January', 'February', 'March',
            \ 'April', 'May', 'June', 'July', 'August', 'September',
            \ 'October', 'November', 'December'])
      return ''
    endfunc

Found it! Tucked away in that Grimoire they are trying to tell us are docs =)

======================= My final script is something like

inoremap <F5> <C-R>=CustomComplete()<CR>

        func! CustomComplete()
                echom 'move to start of last word'
                normal b
                echom 'select word under cursor'
                let b:word = expand('<cword>')
                echom '->'.b:word.'<-'
                echom 'save position'
                let b:position = col('.')
                echom '->'.b:position.'<-'
                normal e
                normal l
                echom 'move to end of word'     

                let b:list = ["spoogle","spangle","frizzle"]
                let b:matches = []


                echom 'begin checking for completion'
                for item in b:list
                echom 'checking '
                echom '->'.item.'<-'      
                        if(match(item,'^'.b:word)==0)
                        echom 'adding to matches'
                        echom '->'.item.'<-'      
                        call add(b:matches,item)
                        endif
                endfor
                call complete(b:position, b:matches)
                return ''
        endfunc
share|improve this answer
    
I dare you to find any documentation as complete as the Vim documentation though. –  Swiss May 22 '12 at 5:39
    
Vim is madness. Complete insanity what you can do with it. –  James Andino May 22 '12 at 5:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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