• You are not logged in.
  • Index
  • General
  • Text expansion/completion in Sublime text

    Text expansion/completion in Sublime text

    • Started by pinkyache
    • 8 Replies:
    • Reputation: 7
    • Registered: 21-Apr-2010
    • Posts: 818

    I just installed Autokey on Linux (thank you whoever mentioned it), and was giving it a test run in Sublime text.

    Anyway I wasn't getting quite the expected behaviour with Autokey, and then I realised that Sublime was doing its own thing with its own auto-completion.

    I've noticed this before when editing CSS stylesheets, but haven't really leveraged it (not sure how fast it is either).

    Example/howto:

    If you have written the word 'background' in your document previously, when you next want to produce it: type 'b' then 'a' and then hit 'tab'.   If you have other words in your document that present ambiguity, then you can further hit tab to cycle through candidates.

    What I didn't realise was that you can also use other combos:  'b' then 'd' followed by 'tab'.  Even 'b' then 'n' followed by 'tab'.

    I'm not sure about limitations here, or if it's practically useful, or how expensive it is to implement.  (I think in Sublime parlance this is buffer auto-completion.) 

    As people have been talking about shorthand they might be interested. You could do poor man's shorthand this way.

    You can write your own files by the looks of things in JSON:
    http://sublimetext.info/docs/en/extensi … tions.html

    I'd be tempted almost to throw a small dictionary at it (or dictionary of difficult words), though not sure how performant it would be.  The ambiguities may prove a problem.

    (Yeah, yeah, I'm sure you can do something similar with Vim and Emacs...)

    Last edited by pinkyache (28-Jan-2014 19:29:00)

    --
    Physicians deafen our ears with the Honorificabilitudinitatibus of their heavenly Panacaea, their sovereign Guiacum.

    Offline
    • 0
    • Reputation: 7
    • Registered: 21-Apr-2010
    • Posts: 818

    Here is an example completions file (Sublime text 2):

    {
            "scope": "text.plain",
            "completions":
            [
                    { "trigger": "me", "contents": "him" },
                    { "trigger": "coke", "contents": "gin" },
                    "antiquated",
                    "antidisestablishmentarianism",
                    "shorthand",
            ]
    }

    Create a file with the above contents and save to: /path/to/sublime/packages/User/shorthand.sublime-completions

    Then in Sublime open a blank text document.

    Try typing:

    'sh' followed by 'tab' results in 'shorthand'.
    'am' followed by 'tab' results in 'antidisestablishmentarianism'.
    'std' followed by 'tab' results in 'shorthand'.
    'ad' followed by 'tab' toggles between 'antidisestablishmentarianism' and 'antiquated'
    'me' followed by 'tab' results in 'him'.
    'co' followed by 'tab' results in 'gin'.
    etc.

    Pretty neat.

    There are probably better ways to work with spelling dictionaries in sublime, but this might be useful to someone.

    Last edited by pinkyache (28-Jan-2014 16:02:57)

    --
    Physicians deafen our ears with the Honorificabilitudinitatibus of their heavenly Panacaea, their sovereign Guiacum.

    Offline
    • 0
    • Reputation: 0
    • Registered: 04-Apr-2013
    • Posts: 538

    I'm not positive, but I don't think emacs' auto-complete mode, even with fuzzy matching, does this.  A search, however, turned up something far out: https://www.emacswiki.org/emacs/HippieExpand

    Offline
    • 0
    • Reputation: 2
    • Registered: 13-Nov-2013
    • Posts: 48

    There is a way to do text expansion in almost every editor that is used for coding, it's not just Sublime. I've used the following and have set up the same expansions in all, Ecplipse, IntelliJ, vim, emacs, and Textmate.

    Just letting you know that while it's a great feature it's by no means localized to a single program.

    Offline
    • 0
    • Reputation: 7
    • Registered: 21-Apr-2010
    • Posts: 818

    @lalop, are you not positive as in you don't like the way it works?

    @jsmithy, granted.  Normally when you expand text, you start with the first few characters then say hit tab.  With sublimeyou can expand other combos:  'sb' might expand to 'sublime', I haven't seen that in other editors.   Also sublime by default will complete from the existing source/buffer.  That's quite handy.

    Having auto-complete files for each editor is a bit of a bind though isn't it?  Even if you can do it.  I'd rather a word/looker-upper/helper/completer available across the operating system, that had some contextual scoping.

    The fuzzy searching (as Sublime supports: something like typing 'arc' to output 'avarice') could be used as a method to sidestep pre-building your own list of shorthand / word mappings.  In sublime you could place an entire dictionary into a sublime auto-complete file (if it would support it).  You could then expand any word from a selection of constituent characters.

    Mind you, I checked the term 'arc' against the dictionary (gcide) with a similar fuzzy match, and I discovered 1075 candidate words so it wouldn't be that practical.   You'd have to up the term length to reduce the candidate matches.  Or come up with a better helper interface.

    The following command,  does a regex search against the gcide dictionary and counts the amount of matched words:

    $ dict -d gcide -m -s re '^a[a-z]*r[a-z]*c[a-z]*$' -f | awk '{print $4}'| wc -l

    The pattern matches words that begin with 'a', with 'r' and 'c' occuring anywhere in the word after, but with 'c' after 'r'.

    (This has probably lead me down a rabbit hole of pattern matching and filtering.)

    Last edited by pinkyache (01-Feb-2014 19:51:35)

    --
    Physicians deafen our ears with the Honorificabilitudinitatibus of their heavenly Panacaea, their sovereign Guiacum.

    Offline
    • 0
    • Reputation: 0
    • Registered: 04-Apr-2013
    • Posts: 538

    s/positive/sure

    To clarify, I'm looking for at least "flex"/"smart" text expansion as pinky describes, ideally with an "auto-complete"-like dialog rather than snippet-like.  There's no technical reason we couldn't have ido/flex/whatever for auto-completions like we do for command-completions, so I feel like I'm probably missing something.  I'll see if I can get it working with "Hippie Expand".

    Last edited by lalop (29-Jan-2014 07:53:53)
    Offline
    • 0
    • Reputation: 0
    • From: London, UK
    • Registered: 09-Nov-2013
    • Posts: 270
    pinkyache said:

    I just installed Autokey on Linux (thank you whoever mentioned it)

    That was me, and you're welcome.

    T9-QWERTY - my port of T9 to the PC (a work in progress); T9-MOUSE - COMING SOON
    Keyboard Shorthand

    Offline
    • 0
    • Reputation: 7
    • Registered: 21-Apr-2010
    • Posts: 818

    Angelic Sedition suggested it with reference to auto-completion.

    --
    Physicians deafen our ears with the Honorificabilitudinitatibus of their heavenly Panacaea, their sovereign Guiacum.

    Offline
    • 0
    • Reputation: 0
    • From: London, UK
    • Registered: 09-Nov-2013
    • Posts: 270

    Ah, so he did. I also suggested it in my T9-QWERTY thread, so you might have seen it mentioned there.

    On that note, have you tried using it for T9-QWERTY?

    And presumably you have found that it works cross-application?

    T9-QWERTY - my port of T9 to the PC (a work in progress); T9-MOUSE - COMING SOON
    Keyboard Shorthand

    Offline
    • 0
      • Index
      • General
      • Text expansion/completion in Sublime text