Toggle *Settings > Editor > Show line numbers" via Command Palette

Use case or problem

I have worked on software my whole adult life. Sometimes I feel disoriented when I cannot see line numbers on the left of a long file. Sometimes I write really long notes in Obsidian. I love Obsidian.

  • Yes, there is a scroll bar which indicates position in the document; however, while jumping around my notes, I often yearn for a quick read on the file size, and invariably end up looking left for line numbers.
  • Yes, I can enable line numbers everywhere all the time via the option in Editor settings. But part of the beauty of Obsidian is itā€™s clean content presentation. I donā€™t want to see line numbers most of the time; yet, sometimes, Iā€™m lost without them, albeit momentarily.

Proposed solution

Obsidian has a global setting *Options > Editor > Display > Show line numbers". I propose that this option can be toggled via the Command Palette, whereby users can reach it quickly and potentially even assign it a hotkey should they see fit.

I personally have found myself searching the Command Palette for this option numerous times as a new user, as it seems like a natural fit. I can understand not wanting to crowd the Command Palette with every option under the sun. Perhaps a settings for ā€œexpose all settings in Command Paletteā€ could work here, but I digress. I just think toggling line numbers should be a first class command.

Current workaround (optional)

Command+, for settings, Control+/ to activate Shortcat, type ā€œeditorā€ and Return, Control+/ for Shortcat again, look for key combination of radio input for line numbers, enter key combination and press Return, press Escape to exit settings.

Related feature requests (optional)

1 Like

You might be also interested using Advanced URI community plugin to access setting pages:

Shell (mac):

open "obsidian://advanced-uri?&settingid=editor&settingsection=Display"

Using Raycast quicklinks:

obsidian://advanced-uri?&settingid=editor&settingsection=Display

You can specify vault parameter i.e. advanced-uri?vault=myVault&ā€¦ if you want to target specific vaults. Without vault parameter advanced uri targets your last used vault.

Other settingids: https://publish.obsidian.md/advanced-uri-doc/Actions/Settings+navigation

The cool thing about Raycast is that you donā€™t necessarily want to use keyboard shortcuts for every actionā€”just use āŒ˜Space and then search your action.

1 Like

Thanks @blue_emperor! This was definitely an improvement on my Mac. And I already had Raycast installed :).

I ended up finding a cross platform solution including optional hotkeys. I have a custom CSS snippet and snippet-commands-obsidian installed, which exposes commands to toggle CSS snippets via the Command Palette.

/* snippet: hide-line-numbers */
.cm-gutters .cm-gutter.cm-lineNumbers {
    display: none !important;
}

Steps:

  1. Add CSS snippet to Obsidian Vault
  2. Install and enable Snippet Commands
    • Any CSS snippets loaded from .obsidian/snippets are now available by name as toggle commands in the Command Palette. In this case, a new command Snippet Commands: Toggle hide-line-numbers is available.
    • No additional plugin config needed
  3. Optional: Map a hotkey for the new command in Settings > Hotkeys
  4. Restart Obsidian. This would remove any modifications made in DevTools debugger while testing the CSS snippet if it were to be forgotten and confuse a silly programmer such as myself.

Itā€™s working well on macOS and iOS so far between restarts and device syncs.

toggle line numbers mac

toggle line numbers ios


<aside>I wish Obsidian would implement a built in way to change settings via a command palette like interface. Maybe as a separate picker interface or by enabling an option as it might cause new users to get stuck accidentally triggering settings updates. Iā€™m kinda paranoid about running so many community plugins if I were to really adopt obsidian as my full pkm/second brain/GTD datastore. Thatā€™s not to say anything against all the wonderful community contributors though. Much love. </aside>

Hi. There is also Code Editor Shortcuts community plugin that introduces toggle line numbers command.