Getting the pipe shortcut to work in Positron

Wait 5 sec.

[This article was first published on Data Analytics and AI Archives - Giles, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.TLDR: For the life of me, I couldn’t get Ctrl+Shift+M to work for inserting pipes (|>) when editing a Quarto document in Positron visual mode. After countless hours fiddling with keybindings.json, I developed a functional, but obtuse workaround for Windows. It’s not pretty, but it works. This post outlines the approach in case it helps others facing the same problem. Note: this problem is already on the radar of the development team, so will no doubt be fixed soon. I’ve also only outlined a workaround for Windows. Feel free to reach out if you’ve found a better solution (or a solution that works on other platforms) and I’ll add this to the post.The problemI’m a big fan of Quarto as it provides a seamless way to mix data, code and narrative text without ever leaving my IDE. I’ve also been trying to move from RStudio to Positron as I find it snappier, works better with AI tools and works well with Python. Unfortunately, Positron is still experiencing growing pains as a newish IDE, including some shortcuts not working when editing Quarto documents in visual mode. This isn’t a new issue (e.g: 1, 2 and 3), so is sure to be fixed in the not-too-distant future (likely just after I post this). But, after countless hours messing around with keybindings.json and hassling people from Posit (apologies, Isabella) I asked Claude if it had a solution. It did.And it works.So, I thought I’d share it here, despite the fact it doesn’t spark joy with the minimalist inside of me:Duct tape and thumbtacks: intercept the shortcut before it reaches PositronAs far as I can tell, the problem comes from Positron / VSCode intercepting some shortcuts when Quarto is in visual mode, which is probably why adjusting the settings did nothing for me. As a (temporary) solution to this, Claude suggested installing a program called AutoHotkey v2 and creating a script operates when Positron is active. Obviously, as an independent-minded person I did what I’m told and here’s how you can do the same:1. Install AutoHotkey v2Get Version 2 from autohotkey.com (the code below will not run under v1).2. Create the script Open Autohotkey2 (or AutoHotKey Dash) and select New Script to create a new blank .ahk script in a secluded folder of your choice. Give it a name like ‘positron-keys.ahk’ so future you knows what it’s doing there and use a text editor to replace the contents of the file with the code below (or the equivalent depending on your shortcut preferences):(SendText sends the literal characters to the Quarto document, so nothing gets re-interpreted by Positron, while #HotIf restricts the behavior to Positron, so it doesn’t interfere with other applications.)#Requires AutoHotkey v2.0#SingleInstance Force#HotIf WinActive("ahk_exe Positron.exe")^+m::SendText(" |> ") ;Ctrl+Shift+M -> native pipe!-::SendText("