Sublime Forum

Markdown Lists: Bullets don't auto-add on enter

#1

In TextMate, when making a bulleted list, hitting enter automatically inserts "* " on the next line. Hitting enter again removes the "* " for the current line and inserts another newline.

Sublime Text 2 doesn’t do this, though seems to be using the same markdown bundle, and I can’t figure out why. It’s driving me crazy having to hit type all the extra "* " while taking notes in class. This is literally the last feature keeping me from switching to subl full time.

Example 1 (in TM, the pipe character | is the curser position):

* this is my list|

Hit return:

* this is my list
* |

Hit return again:

* this is my list

|

Example 1b: same thing in Sublime Text 2

* this is my list|

Hit return.

* this is my list
|

:frowning: Type "* " and waste precious seconds of your life.

* this is my list
* |

Example 2: nested lists (in TM):

* this is my list
  * subitem 1|

Hit return:

* this is my list
  * subitem 1
  * |

Return again:

* this is my list
  * subitem 1

|

Example 3: Ordered lists (in TM):

1. First item|

Hit return:

1. First item
2. |

Another smaller thing I could live without (but may be related) is that TM also auto-wraps headings. That is…

# Heading 1|

Hit return.

# Heading 1 #
|
0 Likes

#2

I have something similar in one of my packages

User/Markdown Add Line.sublime-macro


    {"command": "move_to", "args": {"to": "hardeol"}},
    {"command": "insert", "args": {"characters": "\n"}},
    {"command": "insert", "args": {"characters": "*"}},
    {"command": "insert", "args": {"characters": " "}}
]

User/Markdown Delete Line.sublime-macro


    {"command": "expand_selection", "args": {"to": "line"}},
    {"command": "add_to_kill_ring", "args": {"forward": true}},
    {"command": "left_delete"},
    {"command": "move", "args": {"by": "lines", "forward": false}},
    {"command": "move_to", "args": {"to": "hardeol"}}
]

User/Default.sublime-keymap

    {
    "keys": "enter"], "command": "run_macro_file", "args": {"file": "Packages/User/Markdown Add Line.sublime-macro"},
    "context":  {"key": "selector", "operator": "equal", "operand": "markup.list.unnumbered.markdown", "match_all": true }]
    },
    {
    "keys": "backspace"], "command": "run_macro_file",
    "args": {"file": "Packages/User/Markdown Delete Line.sublime-macro"},
    "context":
      
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\*$", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "markup.list.unnumbered.markdown", "match_all": true }
      ]
    }

It might need some tweaking, but I’m sure you can figure out how to do the wrapping on your own.
It would seem like it would be something worth learning to do. The ordered list might need some plugin work but If you need help or you get it on your own post back and let everyone know :smile:
GL HTH

0 Likes

#3

github.com/erinata/SublimeMarkdown

You may try this.

The code is as bad as it can be because I never wrote python. But it add * - and > automatically in a markdown document.

I will add number list and other things later…

0 Likes