Tuesday, December 23, 2014

Zim Wiki Custom Shortcuts/Keystrokes

NOTE: This solution is not limited to Zim wiki itself. It can be used for any purpose, for any software on your Linux desktop to increase productivity.

I needed to define a custom shortcut for adding Latex equations in Zim wiki. There was no shortcut defined by default and it was cumbersome to every time go to the menu and click on the item using mouse to add an equation.

NOTE: Equation plugin is not enabled by default and you'll have to enable it.

So what I did was install this cool piece of software : Autokey. This is an opensource clone of the ever-popular Windows software Autohotkey.

sudo apt-get install autokey-gtk

Now, we know that to reach the menu item for adding equation can be reached through a few keystrokes in Zim. First we press Alt+i. This opens up the "Insert" menu. Then we press that "q" is highlighted in the "Equation" item in the dropdown menu. This means that pressing "q" will now open the equations dialog. We want this process to be done in a single keystroke.

So, open autokey. Click on New->Script. Add the following code and set a hotkey for the script. I set the hotkey to Alt+e.


Another Example: setting hotkey for adding codeblock

NOTE: You need to have syntax-highlighting plugin enabled.

Just use the following script and set a preferred hotkey.
keyboard.send_key("<up>", repeat=5)
keyboard.send_key("<tab>", repeat=2)
In this example we had to implement a "hacky" way. In this case, if we press Alt+i, then we see that no key in the Codeblock item is highlighted. Hence, can not directly reach there using some alphabet. To reach there, we press UP five times (might be different in your case). Then we press ENTER. After that we press TAB two times to reach OK in the popup dialog, and then we press ENTER.

No comments:

Post a Comment