16

Note: As of version 9, this functionality is available and works out of the box.


I've a few questions about Command Completion in Mathematica. I recently discovered this feature, and it's really convenient. However, it gets tiring to hit Ctrl-K all the time.

Is there a way to turn Command Complete on after every keystroke, like autocompletion is for many programming IDE's?

Or, failing that, to map it to another key like Tab, which I find much more convenient to hit? I've looked up some internet sources on changing Keyboard shortcuts for Mathematica, but they all seem pretty complicated.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Tianxiang Xiong
  • 913
  • 1
  • 7
  • 9

2 Answers2

14

Changing shortcuts isn't that complicated. All you have to do is change one line in the file KeyEventTranslations.tr in a location in your file system specified by this command:

FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
  "TextResources", $OperatingSystem}]

Locate the following line in a text editor and change the key into the one you want:

Item[KeyEvent["F2"], FrontEnd`CompleteSelection[True]]

I wouldn't use tab, as that already has a built-in meaning.

More information can be found here.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
8

You can also use hotstrings as a way of autocompletion. By using such replacements, words are immediately replaced by another word on typing a space after the hotstring:

CreateDocument[{}, InputAutoReplacements -> {"sync" -> SynchronousInitialization}]

You can set such replacements globally under Option Inspector (CtrlShiftO). Of course no one would do it far all built-in commands, but it is useful for the more frequent ones.

István Zachar
  • 47,032
  • 20
  • 143
  • 291