|
| 1 | +# markdown-shortcuts.nvim |
| 2 | + |
| 3 | +<!-- Badges (replace with actual badges) --> |
| 4 | + |
| 5 | +[](https://www.lua.org) |
| 6 | +[](LICENSE) |
| 7 | + |
| 8 | +> Enhancing your Markdown editing experience in Neovim with intuitive shortcuts and commands. |
| 9 | +
|
| 10 | +`markdown-shortcuts.nvim` provides a set of commands and configurable keymaps to streamline common Markdown editing tasks, from inserting elements like headers and code blocks to managing checkbox lists and creating files from templates. |
| 11 | + |
| 12 | +## ✨ Features |
| 13 | + |
| 14 | +- **Insert Markdown Elements:** Quickly add headers, code blocks (with language prompt), bold/italic text, links, tables, and checkbox list items. |
| 15 | +- **Visual Mode Integration:** Wrap selected text with bold, italic, links, or code blocks. |
| 16 | +- **Checkbox Management:** Insert new checkboxes (`- [ ]`) and toggle their state (`- [x]`). |
| 17 | +- **Template Creation:** Create new Markdown files from predefined templates using your choice of picker (`fzf`, `telescope`, `mini.pick`). |
| 18 | +- **List Continuation:** Automatically continue Markdown lists (bulleted, numbered, checkbox) when pressing Enter. |
| 19 | +- **Configurable:** Customize keymaps, enable/disable commands, set template directory, choose picker, and configure Markdown-specific buffer options. |
| 20 | +- **Preview:** Basic preview command (requires external tool configuration). |
| 21 | + |
| 22 | +## ⚡️ Requirements |
| 23 | + |
| 24 | +- Neovim >= 0.8.0 |
| 25 | +- Optional: A picker plugin (`fzf`/`fzf.vim`, `telescope.nvim`, or `mini.pick`) for the template creation feature. |
| 26 | +- Optional: An external Markdown preview tool (like `glow`, `pandoc`, etc.) if using the `MarkdownPreview` command. |
| 27 | + |
| 28 | +## 📦 Installation |
| 29 | + |
| 30 | +Use your favorite plugin manager. |
| 31 | + |
| 32 | +**lazy.nvim** |
| 33 | + |
| 34 | +```lua |
| 35 | +{ |
| 36 | + 'your-username/markdown-shortcuts.nvim', |
| 37 | + -- Optional dependencies for picker: |
| 38 | + -- dependencies = { 'nvim-telescope/telescope.nvim' }, |
| 39 | + -- dependencies = { 'junegunn/fzf', 'junegunn/fzf.vim' }, |
| 40 | + -- dependencies = { 'echasnovski/mini.nvim' }, -- If using mini.pick |
| 41 | + event = "FileType markdown", -- Load when a markdown file is opened |
| 42 | + config = function() |
| 43 | + require('markdown-shortcuts').setup({ |
| 44 | + -- Your custom configuration here |
| 45 | + -- Example: Use Telescope for template picking |
| 46 | + -- picker = 'telescope', |
| 47 | + }) |
| 48 | + end, |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +**packer.nvim** |
| 53 | + |
| 54 | +```lua |
| 55 | +use { |
| 56 | + 'your-username/markdown-shortcuts.nvim', |
| 57 | + -- Optional dependencies: |
| 58 | + -- requires = { 'nvim-telescope/telescope.nvim' }, |
| 59 | + -- requires = { 'junegunn/fzf', run = ':call fzf#install()' }, |
| 60 | + -- requires = { 'echasnovski/mini.nvim' }, |
| 61 | + ft = { "markdown" }, |
| 62 | + config = function() |
| 63 | + require('markdown-shortcuts').setup({ |
| 64 | + -- Configuration goes here |
| 65 | + }) |
| 66 | + end, |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## ⚙️ Configuration |
| 71 | + |
| 72 | +Call the `setup` function to configure the plugin. Here are the default settings: |
| 73 | + |
| 74 | +```lua |
| 75 | +-- Default configuration |
| 76 | +require('markdown-shortcuts').setup({ |
| 77 | + -- Directory containing your Markdown templates |
| 78 | + template_dir = vim.fn.expand("~/.config/nvim/templates"), |
| 79 | + |
| 80 | + -- Picker to use for selecting templates ('fzf', 'telescope', 'snacks'/'mini.pick') |
| 81 | + picker = "fzf", |
| 82 | + |
| 83 | + -- Default frontmatter fields for new files created from templates |
| 84 | + alias = {}, |
| 85 | + tags = {}, |
| 86 | + |
| 87 | + -- Keymappings for shortcuts. Set to `false` or `""` to disable. |
| 88 | + keymaps = { |
| 89 | + create_from_template = "<leader>mnt", -- New Template |
| 90 | + insert_header = "<leader>mh", -- Header (use count for level) |
| 91 | + insert_list_item = "", -- (No default, handled by list continuation) |
| 92 | + insert_code_block = "<leader>mc", -- Code block |
| 93 | + insert_bold = "<leader>mb", -- Bold |
| 94 | + insert_italic = "<leader>mi", -- Italic |
| 95 | + insert_link = "<leader>ml", -- Link |
| 96 | + insert_table = "<leader>mt", -- Table |
| 97 | + insert_checkbox = "<leader>mk", -- Checkbox |
| 98 | + toggle_checkbox = "<leader>mx", -- Toggle Checkbox |
| 99 | + preview = "<leader>mp", -- Preview |
| 100 | + }, |
| 101 | + |
| 102 | + -- Enable/disable specific commands |
| 103 | + commands = { |
| 104 | + create_from_template = true, |
| 105 | + insert_header = true, |
| 106 | + insert_code_block = true, |
| 107 | + insert_bold = true, |
| 108 | + insert_italic = true, |
| 109 | + insert_link = true, |
| 110 | + insert_table = true, |
| 111 | + insert_checkbox = true, |
| 112 | + toggle_checkbox = true, |
| 113 | + preview = false, -- Requires `preview_command` to be set |
| 114 | + }, |
| 115 | + |
| 116 | + -- Command or Lua function to execute for Markdown preview. |
| 117 | + -- Example: 'glow %' (requires glow) or `function() ... end` |
| 118 | + preview_command = nil, |
| 119 | + |
| 120 | + -- Apply local buffer settings for Markdown files |
| 121 | + enable_local_options = true, |
| 122 | + wrap = true, |
| 123 | + conceallevel = 2, |
| 124 | + concealcursor = "nc", |
| 125 | + spell = true, |
| 126 | + spelllang = "en_us", |
| 127 | + |
| 128 | + -- File types where keymaps should be active |
| 129 | + file_types = { "markdown" }, |
| 130 | + |
| 131 | + -- Automatically continue lists (bullet, numbered, checkbox) on Enter |
| 132 | + continue_lists_on_enter = true, |
| 133 | +}) |
| 134 | +``` |
| 135 | + |
| 136 | +## 🚀 Usage |
| 137 | + |
| 138 | +### Commands |
| 139 | + |
| 140 | +The following commands are available (if enabled in `config.commands`): |
| 141 | + |
| 142 | +- `:MarkdownNewTemplate`: Select a template from `template_dir` using the configured picker and create a new file. |
| 143 | +- `:MarkdownHeader`: Insert a header. Prompts for level (1-6) or uses `[count]` (e.g., `:3MarkdownHeader`). In Visual mode, wraps selection. |
| 144 | +- `:MarkdownCodeBlock`: Insert a code block. Prompts for language. In Visual mode, wraps selection. |
| 145 | +- `:MarkdownBold`: Insert `**bold text**`. In Visual mode, wraps selection. |
| 146 | +- `:MarkdownItalic`: Insert `*italic text*`. In Visual mode, wraps selection. |
| 147 | +- `:MarkdownLink`: Insert `[link text](url)`. Prompts for text and URL. In Visual mode, uses selection as text and prompts for URL. |
| 148 | +- `:MarkdownInsertTable`: Insert a table. Prompts for rows and columns. |
| 149 | +- `:MarkdownCheckbox`: Insert a checkbox list item (`- [ ]`). In Visual mode, uses selection as text. |
| 150 | +- `:MarkdownToggleCheckbox`: Toggles the checkbox state (`[ ]` <=> `[x]`) on the current line. |
| 151 | +- `:MarkdownPreview`: Executes the configured `preview_command`. |
| 152 | + |
| 153 | +### Keymaps |
| 154 | + |
| 155 | +Default keymaps are provided (see Configuration). Use them in Normal or Visual mode within Markdown files. |
| 156 | + |
| 157 | +- `<leader>mh`: Insert header (prompts or use count). |
| 158 | +- `<leader>mc`: Insert code block. |
| 159 | +- `<leader>mb`: Insert bold. |
| 160 | +- `<leader>mi`: Insert italic. |
| 161 | +- `<leader>ml`: Insert link. |
| 162 | +- `<leader>mt`: Insert table. |
| 163 | +- `<leader>mk`: Insert checkbox. |
| 164 | +- `<leader>mx`: Toggle checkbox. |
| 165 | +- `<leader>mp`: Preview (if configured). |
| 166 | +- `<leader>mnt`: Create new file from template. |
| 167 | + |
| 168 | +### List Continuation |
| 169 | + |
| 170 | +When `continue_lists_on_enter` is `true`, pressing `Enter` in a Markdown list item (bullet `*`, `-`, `+`; numbered `1.`; checkbox `- [ ]`, `- [x]`) will automatically insert the next list marker on the new line. |
| 171 | + |
| 172 | +## Status |
| 173 | + |
| 174 | +Stable. Contributions and suggestions are welcome. |
| 175 | + |
| 176 | +## Contributing |
| 177 | + |
| 178 | +Please see CONTRIBUTING.md (if available) or open an issue/pull request. |
| 179 | + |
| 180 | +## License |
| 181 | + |
| 182 | +Distributed under the MIT License. See `LICENSE` file for more information. |
0 commit comments