Question: how to insert a Python docstring? #15904
|
Hello there, I've been toying around Helix recently, and one of the little annoyances is the way matching pairs are inserted all together. And it disturbs something a regular Python dev does quite frequently: inserting multi-line docstrings. For the record, a docstring is a quote-surrounded text at the beginning of a function or a class method to explain the goal of the code block. Example (silly, but the most important is the docstring syntax here): def add(x: int, y: int) -> int:
"""
Add to int together and return the result
"""
return x + yIt's not mandatory, but a good practice is to wrap the docstring around multiple double-quotes. In many other code editors I've used in the past (Atom, nvim, Gram, Pulsar, to name a few), I just have to hit the In Helix, it's not that smooth. Hitting Hitting With my poor helix skills, I've managed to build a macro, which is probably far from optimal, and link it to a keyboard shortcut. [keys.normal]
# [..]
"A-g" = '@i""""""<esc>3hi<ret><backspace>'It adds 6 But I was wondering if there was a more elegant and direct way, by any chance? |
Replies: 1 comment 1 reply
|
Hello👋 This is a known limitation and there is an open issue tracking exactly this auto pair behavior with triple quotes: #13697. So its not something you are missing, its a real gap in the current auto-pair logic. A cleaner workaround than a macro: disable auto-pairing for " specifically in Python. [[language]]
name = "python"
[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
"'" = "'"
'`' = '`'Leaving " out of that table turns off auto closing for double quotes in Python files only and other pairs keep auto pairing normally. Then writing a docstring is fully manual: type """, Enter, write your text, type """ on the closing line. No macro or cursor gymnastics needed. Run :config-reload after saving the file. |
Hello👋
This is a known limitation and there is an open issue tracking exactly this auto pair behavior with triple quotes: #13697. So its not something you are missing, its a real gap in the current auto-pair logic.
A cleaner workaround than a macro: disable auto-pairing for " specifically in Python.
Add this to
languages.tomlin your config directory (~/.config/helix/languages.toml on Linux/macOS, %AppData%\helix\languages.toml on Windows):Leaving " out of that table turns off auto closing for double quotes in Python files only and other pairs keep auto pairing normally. Then writing a d…