Skip to content

Smart, Prettier-compatible Markdown auto-bullet list plugin for NeoVim

License

Notifications You must be signed in to change notification settings

yutanagano/smark.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

203 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠🚅 smark.nvim

neovim_plugin MIT_license Tests

Smark is a NeoVim plugin that helps you write and manipulate markdown lists. It has an opinionated design with the following principles:

  1. Correct: only consider and always output valid Markdown lists that have a sane structure (e.g. list block is a clean tree, no sudden jumps in indentation level, correct numbering)
  2. Clean: follow Prettier's style convention
  3. Smart: Automatically infer as much as possible

📋 Features

Feature Demo
Automatic generation of list markers with <CR> (insert mode) or o (normal mode) autobullet
Supports list indentation / nested lists indentation
Indenting multiple items at once multiline_indentation
Toggle between ordered and unordered list types ordered
Support for task list items completion
Toggle between plain and task list items task
Support for multi-line list items multiline
Inference of indent level list type from context type_inference
Automatic updates to indentation rules as necessary indent_spacing
Clearnly turning list items into paragraphs paragraph
Manual triggering of list block formatting format

⚙️ Installation

With lazy.nvim:

return {
  {
    "yutanagano/smark.nvim",
    ft = { "markdown", "text" },
    --Below are the default settings for the available options. You can omit
    --the opts table below and simply set config = true if you are happy with
    --the default settings.
    opts = {
      --Keymapping settings for list action commands.
      --Set to false to disable.
      mappings = {
        --Format the current list block to be clean / correct.
        format_list = "<leader>lf",
        --Switch between ordered / unordered list types.
        toggle_ordered = "<leader>lo",
        --Toggle the completion status of a task list item.
        toggle_completion = "<leader>lx",
        --Toggle between plain and task list items.
        toggle_task = "<leader>lt",
      },

      --Following the starting line of a list item, only contiguous lines that
      --start with at least one whitespace character can be considered as part of
      --a multi-line list item.
      multiline_requires_whitespace = false,
    },
  }
}

Important

The ft = { "markdown", "text" } setting ensures the plugin is lazily loaded only after NeoVim opens a markdown or plain text buffer. However, regardless of lazy loading, the plugin is only active when editing markdown or plain text documents.

💭 Why smark?

I take a lot of Markdown notes in NeoVim. I'm lazy, so 1. I don't like to think about formatting, and 2. I don't want to have to write out lists manually. For the first problem, I use conform.nvim and prettierd to auto-format my Markdown documents at write-time. For the second problem, I previously used the wonderful plugin bullets.vim. I love it, but one thing annoyed me - it didn't play well with Prettier's auto-formatting of lists, specifically the list indentation levels. So, I wrote my own auto-bullet plugin that auto-completes lists in a Prettier-compatible way, which became smark.

Note

Prettier formats nested Markdown lists so that the child list marker aligns with the content of the parent list item, resulting in 2 spaces for unordered lists and enough spaces (usually 3 or more) for ordered lists.

- Foo:
  - Bar

1. Foo
   1. Bar
2. Foo
3. Foo
4. Foo
5. Foo
6. Foo
7. Foo
8. Foo
9. Foo
10. Foo:
    1. Bar

📢 Shout-outs

About

Smart, Prettier-compatible Markdown auto-bullet list plugin for NeoVim

Topics

Resources

License

Stars

Watchers

Forks