lifepillar / vim-mucomplete

Chained completion that works the way you want!
MIT License
913 stars 18 forks source link

Abbrev method #38

Closed lacygoill closed 7 years ago

lacygoill commented 7 years ago

Hello,

since the plugin already implements custom methods like path, spel and ulti, I thought it could be useful to add an abbr method which suggests abbreviations for the word before the cursor.

lacygoill commented 7 years ago

Sorry, I've just realised that the code uses the execute() function. I will try to change it so that it uses :redir instead, since execute() is somewhat new for Vim. I won't be able to do it today, but I'll do it as soon as I can.

lacygoill commented 7 years ago

I replaced execute() with :redir, it seems to work.

You might think that such a method is not very useful, because abbreviations are short by design, but the reason why I tried to implement this, is to make them a little more discoverable. Sometimes you might forget what's the abbreviation for a word or expression.

Usually what I do is look inside my vimrc. But it would be great to be able to see them right from a completion menu, with their meaning ({rhs}) in the description field. It's somewhat similar to the ulti method. Generally the tab triggers are short, so you don't really need completion, but it makes them more discoverable. In particular if you installed a third-party plugin which provides default snippets.

lacygoill commented 7 years ago

By the way, you seem to find ways to improve current existing methods. There's a plugin called unicode.vim. Among other things, it provides the mappings C-x C-g and C-x C-z.

C-x C-g suggests characters whose digraph contains the text before the cursor. C-x C-z suggests characters whose unicode name contains the text before the cursor.

It also provides public functions:

unicode#FindUnicodeBy()
unicode#FindDigraphBy()
unicode#Digraph()
unicode#UnicodeName()

Here's their documentation in case you're interested:


unicode#FindUnicodeBy({match}])         *unicode#FindUnicodeBy()*
    Searches the unicode data for {match} and returns a list of dicts,
    each dict representing one match. The dict can have the following
    keys:
        "name"  Unicode name
        "glyph" Unicode Codepoint
        "dec"   Unicode Codepoint decimal value
        "hex"   Unicode Codepoint hex value
        "dig"   Digraph, to output this Unicode codepoint
            in Vim (see |i_CTRL-K|) (If there
            exists several digraphs, they will be separated
            by a space). This key is optional.
        "html"  Html entity to create this Unicode Codepoint.

    {match} can be a regular expression or a decimal or hex value (in
    which case the unicode characters will be searched for their
    decimal/hex values). Use the prefix "0x" or "U+" to force searching
    for that particular hex value. If {match} is an expression, it will
    be matched against the charactername (and case will be ignored).

unicode#FindDigraphBy({match})             *unicode#FindDigraphBy()*
    Searches the digraphs for {match} and returns a list of dicts for
    each match. The dict can have the following keys:
        "name"  Unicode name
        "glyph" Unicode Codepoint
        "dec"   Unicode Codepoint decimal value
        "hex"   Unicode Codepoint hex value
        "dig"   Digraph, to output this Unicode codepoint
            in Vim (see |i_CTRL-K|) (If there exists
            several digraphs, they will be separated
            by a space). This key is optional.
        "html"  Html entity to create this Unicode Codepoint.

    {match} can be a regular expression or a decimal or hex value (in
    which case the unicode characters will be searched for their
    decimal/hex values). Use the prefix "0x" to force searching for that
    particular hex value. If {match} is an expression, it will be matched
    against the charactername (and case will be ignored).

unicode#Digraph({string})              *unicode#Digraph()*
        {string} needs to be a exactly 2 chars long.
    Returns the digraph of {string}. If it is not valid,
    returns en empty string.

unicode#UnicodeName({val})           *unicode#UnicodeName()*
    returns the unicode name of the character with the decimal value {val}

Maybe it could be used, one day in the future, to add new methods to vim-mucomplete.

lacygoill commented 7 years ago

Oh I've just realised that you already provided a mechanism for the user to add their own completion methods. The user should be able to write something like:

  let g:mucomplete#user_mappings = {
      \ 'abbr'  : "\<c-r>=AbbrComplete()\<cr>"
      \ }

I'm closing the PR. It's probably better to not add an excessive amount of methods and bloat the plugin.