Skip to content

Commit ba1fa5e

Browse files
committed
initial commit
0 parents  commit ba1fa5e

17 files changed

+1737
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Lua
2+
*.luac
3+
4+
# OS generated files
5+
.DS_Store
6+
.DS_Store?
7+
._*
8+
.Spotlight-V100
9+
.Trashes
10+
ehthumbs.db
11+
Thumbs.db

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
### Changed
13+
14+
### Deprecated
15+
16+
### Removed
17+
18+
### Fixed
19+
20+
### Security
21+
22+
## [0.1.0] - 2025-05-04
23+
24+
### Added
25+
26+
- Initial release of `markdown-shortcuts.nvim`.
27+
- Features include: inserting headers, code blocks, bold/italic text, links, tables, checkboxes; toggling checkboxes; creating files from templates; list continuation; configurable keymaps and commands; optional buffer settings.
28+
29+
[Unreleased]: https://github.com/your-username/markdown-shortcuts.nvim/compare/v0.1.0...HEAD
30+
[0.1.0]: https://github.com/your-username/markdown-shortcuts.nvim/releases/tag/v0.1.0

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Magnus Gaarder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# markdown-shortcuts.nvim
2+
3+
<!-- Badges (replace with actual badges) -->
4+
5+
[![Lua](https://img.shields.io/badge/Lua-blue.svg?style=flat-square&logo=lua)](https://www.lua.org)
6+
[![License](https://img.shields.io/github/license/your-username/markdown-shortcuts.nvim?style=flat-square)](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.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Autocommands setup functionality
2+
local M = {}
3+
4+
--- Setup autocommands for markdown files
5+
---@param options table Plugin configuration options
6+
function M.setup_autocmds(options)
7+
-- Create autocommand group
8+
local augroup = vim.api.nvim_create_augroup("MarkdownShortcuts", { clear = true })
9+
10+
-- Set up autocommands for markdown files
11+
vim.api.nvim_create_autocmd("FileType", {
12+
group = augroup,
13+
pattern = "markdown",
14+
callback = function()
15+
-- Set up local options for markdown files
16+
if options.enable_local_options then
17+
vim.opt_local.wrap = options.wrap
18+
vim.opt_local.conceallevel = options.conceallevel
19+
vim.opt_local.concealcursor = options.concealcursor
20+
vim.opt_local.spell = options.spell
21+
vim.opt_local.spelllang = options.spelllang
22+
end
23+
end,
24+
})
25+
end
26+
27+
return M

0 commit comments

Comments
 (0)