thesaurus_query.vim icon indicating copy to clipboard operation
thesaurus_query.vim copied to clipboard

Support for native vim auto-complete and mappings (eg ^X - ^T)

Open petRUShka opened this issue 9 years ago • 6 comments

There is native vim support for thesaurus:

'thesaurus' 'tsr' string (default "") global or local to buffer global-local List of file names, separated by commas, that are used to lookup words for thesaurus completion commands i_CTRL-X_CTRL-T. Each line in the file should contain words with similar meaning, separated by non-keyword characters (white space is preferred). Maximum line length is 510 bytes.

It would be great for that plugin to replace that functionality. Because sometimes it much better for speed and convenience to have autocomplete list.

petRUShka avatar Apr 17 '16 20:04 petRUShka

Hmm. Actually, one of the original motivation for me to create this plugin is that I don't like the menu-like synonym choosing interface, browsing dozens or even hundreds of synonyms one by one could be a very painful experience. I intended to design it to be similar to Vim's spell check function rather than auto-completion functionality, so that all options are displayed nice and clean. And you can choose the synonym with a simple number. But if you want, I guess sending the query result back to Vim's auto-completion is doable. I'll need some time to read-up on how, though.

There is one issue I can think of. If user choose to use this plugin's query result as a source for Vim's auto-completion(after it's made possible). Each auto-complete invoking key-stroke will invoke online query function, which can take seconds to complete. That might pose significant lagging. With async feature provided by NeoVim or Vim 8+, it is possible to reduce the lag time. But that is still yet to be seen.

Ron89 avatar Apr 18 '16 02:04 Ron89

Insert-mode auto-completion is added through completefunc (commit 98a3d20). That is, by <ctrl-x ctrl-u> in insert mode, online-query functionality will be invoked.

Ron89 avatar Apr 21 '16 07:04 Ron89

Great! I'll try it!

petRUShka avatar Apr 21 '16 09:04 petRUShka

By the way. Is it impossible to bind ctrl-X ctrl-T?

petRUShka avatar Apr 21 '16 09:04 petRUShka

When I try to use ctrl-x ctrl-u for Enlish word I catch an error:

WARNING: one or more query backends report error. Please check on thesaurus source(s).    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
Traceback (most recent call last):    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
 File "<string>", line 8, in <module>    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
vim.error: Vim(let):E121: Undefined variable: u 

When I use it for Russian word it is just:

User defined completion (^U^N^P) Pattern not found

When I use <Leader>-cs it works perfectly both for Russian and English.

petRUShka avatar Apr 21 '16 09:04 petRUShka

The issue is likely caused by:

  1. the decoding of utf-8 characters. Implementing it was an afterthought, so there were a lot of inconsistencies in the code.
  2. Vim 7.3 don't accept decoded unicode string return from Python while Vim 7.4 do, hence when there are Russian words, Vim 7.3 tend to report error when result is returned from Python.

In latest commits(1b323a6), I have systematically went through all the encoding details within modules. It should work fine at this point(I have already tested it on OS X and Linux, both Vim 7.3 and Vim 7.4).


Your

User defined completion (^U^N^P) Pattern not found

for Russian query is possibly caused by not setting g:tq_language or buffer specific b:tq_language correctly. You should set it to either ['ru', 'en'] or 'ru' in your ~/.vimrc to activate Russian synonym query.


I don't know if overriding ctrl-X ctrl-T is possible. As far as I know, the documentation of Vim didn't cover it. And I don't believe it's as simple as remapping. But after reading Vim's documentation, I find completefunc flexible enough for me to implement the insert-mode autocompletion functionality, so I coded as such.

Hope you find the fixed plugin better suited your working style. :D

Ron89 avatar Apr 22 '16 11:04 Ron89