Quick Formatting in OneNote Using Slash Commands

NOTE: This solution only works in Windows. Tested for both OneNote for Windows 10 and the OneNote Desktop App

Slash commands are used in many programs to quickly select content type, or perform some other defined action by typing / followed by a command word. In Notion and Confluence, for example, you can type /h1 to insert an H1 Heading into your page:

Having Slash commands in OneNote would be great, though OneNote doesn’t natively come with this functionality (yet!). However, using AutoHotkey, you can very easily simulate having Slash commands in OneNote to quickly change the format or style, add or remove tags, or whatever else you can think of.

AutoHotkey is a free, open-source scripting language that is very simple and quick to get setup and working with immediately. Visit Running Your First AutoHotkey Script for how to install AHK and run a script.

CREATING SLASH COMMANDS FOR ONENOTE

OneNote has built-in keyboard shortcuts for some of their styles. For example, Alt+Ctrl+1 will select the Headings 1 style (likewise for Headings [2-6]). We will use built-in these keyboard shortcuts in developing our OneNote Slash commands.

To start, let’s define our Slash command for the Heading 1 style.

  1. When we type /h1 on a page in OneNote, we would like the block we are editing to change to Heading 1. In AutoHotkey, when you want to type a string of characters as your trigger (as opposed to using a hotkey), Hotstrings are the way to go.
  2. We only want these Slash commands to work in OneNote. We will also use the #If directive which will allow us to specify that the hotstring should only trigger when OneNote is the active window.
  3. Lastly, we want this to trigger immediately once /h1 is typed. Therefore, we will use the * Hotstrings option so we don’t have to wait for an end character (like a space or enter key to be pressed).

Here is the AutoHotkey script:

#If WinActive("‎- OneNote ahk_class ApplicationFrameWindow", "OneNote") or WinActive("ahk_exe ONENOTE.EXE")

:*:/h1::!^1

Just 2 lines and we are up and running with our Slash command! Once you run the script, anytime you type h1 into your OneNote page, it will change the style to Heading 1.

HOW IT WORKS

#If WinActive("‎- OneNote ahk_class ApplicationFrameWindow", "OneNote") or WinActive("ahk_exe ONENOTE.EXE")

:*:/h1::!^1
  1. The first line is an #If directive. The #If directive sets up context-sensitivity so that any hotkeys or hotstrings (in our case) defined below it will only activate if the condition is met.
    • We check if either the OneNote for Windows 10 or the OneNote desktop app are the active windows in order to run our Slash command hotstring.
  2. We then define the hotstring.
    • * is an option that will trigger the hotstring immediately after it is typed.
    • /h1 is the text string that needs to be typed to trigger to hotstring for our Slash command.
    • Finally, we send ALT+CTRL+1 as soon as /h1 is typed. ALT = !, CTRL = ^, 1 = 1. These are special modifier key symbols that instruct AHK you want to hold the ALT + CTRL down while pressing 1.

MORE SLASH COMMANDS FROM BUILT-IN ONENOTE SHORTCUTS

Now that we’ve built one Slash command, we can continue to add more hotstrings to our script for our most-used styles and tags in OneNote that have built-in hotkeys.

Here are the ones I use most often, and what I would like to use for the Slash command definition. You can, of course, change the slash commands to what suits you best.:

Slash CommandOneNote Style or TagOneNote Built-in Hotkey
/h1/h6Headings 1-6CTRL + ALT + 1-6
/n Normal StyleCTRL + SHIFT + n
/todo To Do [Tag]CTRL + 1
/imp Important [Tag]CTRL + 2
/q Question [Tag]CTRL + 3

And here is the corresponding AHK script for the hotstring definitions of these OneNote Slash commands:

#If WinActive("‎- OneNote ahk_class ApplicationFrameWindow", "OneNote") or WinActive("ahk_exe ONENOTE.EXE")

:*:/h1::!^1
:*:/h2::!^2
:*:/h3::!^3
:*:/h4::!^4
:*:/h5::!^5
:*:/h6::!^6

:*:/n::^+n
:*:/todo::^1
:*:/imp::^2
:*:/q::^3

What’s great about these slash commands is that you don’t have to type them at the start of the line. You can change the line to have whatever style or format you want by typing the Slash command at any time. Here’s an example of that in practice, changing a normal text line to add the To Do tag by typing /todo at the end of the line:

What kind of Slash commands will you be adding to OneNote?