Home Download Buy Blog Forum Support

Automatic Text Substitution

Automatic Text Substitution

Postby dansheffler on Mon Apr 23, 2012 4:59 pm

I looking for something in Sublime to automatically replace certain strings as I type with other strings. For example, I would like each instance of "cliche" as I type to be automatically replaced by "cliché." I have experimented a little with snippets to accomplish this, but is there a way to do it without pressing tab and simply having it happen in the background as I type? It also seems like overkill to have a separate snippet file for each word I would like to automatically replace.
dansheffler
 
Posts: 3
Joined: Sat Apr 21, 2012 2:17 am

Re: Automatic Text Substitution

Postby agibsonsw on Mon Apr 23, 2012 5:51 pm

I also find it unnecessary to have a load of separate snippet files, when a 'sublime-completions' file can be both a simple list of words and snippets. Have a look at 'PHP.sublime-completions' to give you the idea. But accented characters may require a snippet to embed their hex character code.

However, they would still require pressing Tab, or Enter, to complete the word. "Auto-correction", similar to MS Word, could be achieved using the 'on_modified' event to monitor, and correct, text as you type (I'm not sure I'd fancy the overhead involved with this). Or, less intrusive, would be to create a TextCommand that looks for and replaces a list of words that you maintain on pressing a keyboard-combination.

Anyway, you could create a 'yourname.sublime-completions' file and store it in your 'Packages\User' folder that looks like this:

Code: Select all
{
   // "scope": "source.php - variable.other.php", // remove this line if you want it to work for all files

   "completions":
   [
      "cliché", "wibble", "nee",

      { "trigger": "cliche", "contents": "clich\x{C3A9}" },
      { "trigger": "acos", "contents": "acos(${1:arg})" }
   ]
}

I haven't tested whether C3A9 is the correct code-number, or whether it requires double-escaping '\\'. The inner curly brackets may even need to be escaped :). That is, using '\{C3A9\}' or double \. (Sorry, being a bit lazy..). Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Automatic Text Substitution

Postby itaiferber on Tue Apr 24, 2012 2:23 am

Don't know what OS you're running, but it sounds to me like this would work better for you on the OS level. On the Mac, there are tools like TextExpander that you can use to automatically replace what you type with other words (and fix common misspellings) - I'm sure other OSes have comparable applications that do the same thing.
itaiferber
 
Posts: 15
Joined: Mon Apr 16, 2012 1:04 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Yahoo [Bot] and 19 guests