Sort text selection alphabetically

Use case or problem

When I create a list of items in Obsidian, I’d like to sort that list alphabetically.

Proposed solution

I like the implementation that Visual Studio Code uses:

  1. Select the text you want to sort.
  2. Type Shift + Ctrl + P to bring up the list of commands.
  3. Type ‘sort’.
  4. Either choose ‘Sort lines ascending’ or ‘Sort lines descending’ depending on how the user wants to sort.

Optional feature

Perhaps it would be nice if Obsidian can ignore the links when sorting. That way…

- [[MOC_A]] Habits
- [[MOC_B]] Attitude & character

Becomes…

- [[MOC_B]] Attitude & character
- [[MOC_A]] Habits

And…

- [[2020-12-22 075926]] Personal studies
- [[2020-12-22 083319]] All studies

Becomes…

- [[2020-12-22 083319]] All studies
- [[2020-12-22 075926]] Personal studies

Current workaround (optional)

The current workaround is to launch Visual Studio Code, paste the note’s content in a new file there, sort using the method described above, and then copy the note’s content back in Obsidian.

This workaround is not ideal because Visual Studio Code doesn’t know that [[ and ]] is an Obsidian link that is likely not important when sorting.

Related feature requests (optional)

I searched the forum with ‘sort alphabetically’ and ‘order alphabetically’ but didn’t find related feature requests.

13 Likes

I agree. There are a lot of good reasons to be able to easily alphabetize. Perhaps you missed my previous request when you searched because I used the word “alphabetize” not “alphabetically”. Here is my request, not that I received much of a response: Alphabetize/Remove Duplicates
And since I posted that request, I have found out you can remove duplicates as a filtering function in LibreOffice calc (and I am sure in Excel and the rest).

Also, as a side note, if you use Advanced Tables plugin in Obsidian, you can sort alphabetically by column, which is pretty cool.

Use case described in original post is one of the reasons why I prefer markdown links because they have the human readable text aligned to the left. With wikilinks, alignment is achieved only when all IDs are the same length.

Instead of …

- [[AnyID|Attitude & character]]
- [[2020-12-22 075926|Personal studies]]
- [[2020-12-22 083319|All studies]]

… I have

- [Attitude & character](AnyID)
- [Personal studies](2020-12-22 075926)
- [All studies](2020-12-22 083319)

Since Obsidian Release v0.10.2, markdown links are clickable in edit mode. IDs can be hidden by switching to preview mode, but with markdown links they do not intrude on the left edge even in edit mode, especially when IDs do not have standardized length.


I also think that this request has better chance to be implemented as a plugin which will be open source and allow to add tweaks like for example sorting wiki-links while ignoring initial link-target part or ignoring links completely as requested in original post.
So I would suggest merging this request with Alphabetize/Remove Duplicates

Edit 2021-02-06:
The plugin is here: https://github.com/Vinzent03/obsidian-sort-and-permute-lines

I use custom AutoHotkey script for sorting not only simple lines but also nested blocks as units, according to lowest detected indentation level and with some processing to e.g. ignore quotation marks and [] brackets when determining sort order, perhaps link id’s could be eliminated too with some code modification. It also sorts comma separated lists. If you are interested, I could try to extract it from my code-base.

- item B
  - sub-item 1
- item A
  - "sub-item" 2

becomes

- item A
  - "sub-item" 2
- item B
  - sub-item 1
1 Like

Thanks, yes I did not found your request. It looks interesting and I haven’t thought about a plugin request for this.

But I do think your request is different from mine: you want to alphabetise and remove duplicates in one go it seems. And while I’d like alphabetisation features, I definitely don’t want Obsidian or a plugin to remove entries. :slightly_smiling_face:

Thanks for sharing your input. I prefer to place my identifiers before the note, so that everything is nicely aligned and scanning goes a lot quicker.

Thanks but I do almost all my work in edit mode. So this approach might work for your workflow, but not for mine.

I don’t think this is a good idea. Who is going to make those tweaks to the open source plugin? Not me since I don’t know how.

I disagree. That plugin requests asks for a feature that alphabetises and removes duplicates in one go. But I don’t want to remove duplicates, so if someone makes that plugin I couldn’t use it to achieve the goal of this feature request.

1 Like

I agree this being an important request, perhaps it might be more of a plugin thought.

@JkNML as a current way to workaround this problem I use spacemacs for this kind of things, like you said VS code works too.

My only recommendation is that instead of copy pasting into vs code, it’s a lot better if you open the original file in VS code and edit it, since it’s a plain text file you can use it anywhere and it will update in OBsidian, so there’s no need to copy paste and copy paste back, since you can just manipulate the orginal file in VS Code.

That might make things simplier for now.

Hope that helps

1 Like

Additionally, if VS Code is set as default app in OS for opening .md files, then we can open it
directly from Obsidian for advanced operations on file by Obsidian → Settings → Hotkeys → Open in default app

2 Likes

exactly, that’s a good tip to simplify the process even further. There will always be limitations to obsidian that other text editors can be used instead.

Of course it’s awesome to have as much capability inside of obsidian, but things like this might have to be community plugins.

Thankfully there are a lot of text editor that have this advanced capabilities and since everything is plaintext it should be pretty easy,but I do understand the wish to have it all in Obsidian.

This is a needed feature. I love having lists, but they expand over time, and it’s time consuming to manually sort

There is a plugin called Sort and Permute (https://github.com/Vinzent03/obsidian-sort-and-permute-lines) which can sort text but it can’t (yet) do the sorting ignoring links.

2 Likes

an easy suggestion using atom.io