Git Product home page Git Product logo

md-headers.nvim's Introduction

Markdown Headers

Markdown Headers is a simple/basic Neovim plugin that allows you to easily navigate between headings in a Markdown file.

preview

Why use Markdown Headers?

  • It saves time and effort when navigating long and complex markdown documents.
  • It works for both Markdown and HTML headings.
  • It helps you keep track of your location in the document.
  • It can improve your productivity and efficiency when writing or editing markdown documents.

There are probably plenty of other plugins that do the exact same thing and are probably nicer to look at ๐Ÿ˜…, feel free to use them. I only made this plugin to learn a bit more about the Neovim API and for FUN ๐Ÿ˜‰.

Limitations

Currently, the plugin is only able to recognize and extract headings that are constructed on a single line. This is because the regular expression used to match headings only looks for the start and end tags of a heading element on the same line.

# Heading
<h1>Heading</h1>

Headings that span multiple lines, such as the one shown in the example below, will not be recognized by the plugin because the start and end tags are not on the same line. This means that the regular expression will not match the heading, and it will not be included in the list of headings displayed in the popup window.

<h1>
    Heading
</h1>

I understand that this limitation may be frustrating, and I apologize for the inconvenience. I am open to considering adding support for headings that span multiple lines in the future. If you would like to see this feature implemented, please feel free to submit a pull request or open an issue. Your contributions are always welcome and appreciated ๐Ÿ˜€!

Installation

Using Packer

  1. Add this to your Neovim config:
use {
    'ESSO0428/md-headers.nvim',
    requires = {
        'nvim-lua/plenary.nvim'
    }
}
  1. Run :PackerSync to install the plugin on your machine.

Using Vim-Plug

  1. Add the following to your Neovim config:
Plug 'nvim-lua/plenary.nvim'
Plug 'ESSO0428/md-headers.nvim'
  1. Run :PlugInstall to install the plugin on your machine.

Manually

  1. Clone this repository into your Neovim ~/.config/nvim/pack/plugins/start/directory.

Configuration

You can configure the plugin by adding the following to your init.lua:

Configuring Markdown Headers in init.vim

All the examples below are in lua. You can use the same examples in .vim files by wrapping them in lua heredoc like this:

lua << END
    require('md-headers').setup()
END

Configuring Markdown Headers in init.lua

Here is an example of how you can configure the plugin in your init.lua file. The example below shows the default configuration, which you can customize by modifying the values of the different settings.

local md_headers_status_ok, md_headers = pcall(require, 'md-headers')
if not md_headers_status_ok then
    return
end

-- Configure the popup window settings.
md_headers.setup {
    width = 60,
    height = 10,
    borderchars = { 'โ”€', 'โ”‚', 'โ”€', 'โ”‚', 'โ•ญ', 'โ•ฎ', 'โ•ฏ', 'โ•ฐ'}
}

-- Shorten function name.
local keymap = vim.keymap.set
-- Silent keymap option.
local opts = { silent = true }

-- Set keymap.
keymap('n', '<leader>mdh', ':MarkdownHeaders<CR>', opts)
keymap('n', '<leader>mdhc', ':MarkdownHeadersClosest<CR>', opts)

You can customize the following settings:

  • width: The width of the Markdown Headers popup window.
    • For example, setting the width to '100' will result in the popup window being 100 columns wide.
  • height: The height of the Markdown Headers popup window.
    • For example, setting the height to '30' will result in the popup window being 30 lines high.
  • borderchars: The character that will be used to draw the border around the popup window.
    • For example, setting the borderchars to '{ '', '', '', '', '', '', '', '' }' will result in the popup window being drawn without a border.

If you do not configure Markdown Headers or leave certain settings unconfigured, it will use its default settings for those settings.

NOTE: This will start Markdown Headers with it's default configuration (refer to the header above).

Usage

To use the Markdown Headers plugin, use the :MarkdownHeaders command to display a list of headings in the current buffer in a floating window. The headings will include both Markdown and HTML headings. You can navigate to a heading by pressing Enter on it, and the cursor will move to the corresponding heading in the main window. You can also press Escape or q to close the window. The window will also close automatically when you've selected a heading.

To start the plugin with the cursor already positioned on the closest heading, use the :MarkdownHeadersClosest command instead.

Examples:

:MarkdownHeaders
:MarkdownHeadersClosest

License

Markdown Headers is licensed under the MIT License. See the LICENSE.md file for more information.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.

TODO

  • Support headings that are spread across multiple lines.
    • HTML only.
  • To be continued...

md-headers.nvim's People

Contributors

antonvanassche avatar esso0428 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.