Coder Social home page Coder Social logo

vim-md-link's Introduction

link.vim

Warning

This plugin now supports not only Markdown links, but also plaintext links, hence the renaming of the plugin. This update includes several breaking changes, so please read this document and :help link.

link.vim is a plugin for Vim and Neovim that keeps long URLs out of your way. It supports links in Markdown syntax and plaintext links (e.g. in emails, in text files etc.)

Inline links will be moved to a reference section. For instance, the following Markdown document:

# Notes

[Vim](https://www.vim.org) and [Neovim](https://neovim.io) are text editors.

will be turned into

# Notes

[Vim][0] and [Neovim][1] are text editors.

## Links

[0]: https://www.vim.org
[1]: https://neovim.io

Watch the screencast for a quick overview of the plugin:

screencast.mp4

Installation

Use your favorite plugin manager to install this plugin. For instance, if you use vim-plug:

Plug 'qadzek/vim.link'

Usage

By default, this plugin is activated for Markdown, Vimwiki, email and text files. You can customize the filetypes on which the plugin operates in your vimrc:

let g:link_enabled_filetypes = [ 'markdown', 'gitcommit' ]

link.vim can be used by executing one of the following commands:

Command Key binding Description
:LinkConvertSingle LocalLeader + c Convert link under cursor
<C-g> + c Same, but from insert mode
:LinkConvertRange LocalLeader + c Convert links on visually selected lines
:LinkConvertAll LocalLeader + a Convert all links in document
:LinkJump LocalLeader + j Jump to and from reference section
:LinkOpen LocalLeader + o Open link in browser
:LinkPeek LocalLeader + p Show link preview
:LinkReformat LocalLeader + r Renumber/merge/delete unneeded links

No mappings are built-in to avoid conflicts with your existing key bindings. You can enable the key bindings suggested above by adding this line to your vimrc:

let g:link_use_default_mappings = 1

Note that by default, <LocalLeader> is the backslash key. Run :help link-mappings to view how to change these key bindings.

Read :help link-configuration to learn how to customize the heading, the position of the reference section, which lines to skip and more.

The Wiki contains some snippets submitted by users, showing configuration for e.g. gitcommit buffers.

Misc

Questions, suggestions, comments, feature requests... everything is welcome in the Issues tab.

If you would like to contribute, see :help link-contributing.

vim-md-link's People

Contributors

qadzek avatar konfekt avatar

Stargazers

tyr898 avatar  avatar VimWei avatar Bence Ferdinandy avatar  avatar Uwe Sommerlatt avatar Aditya Gaitonde avatar rein avatar  avatar Dan Bungert avatar

Watchers

 avatar

Forkers

konfekt

vim-md-link's Issues

convert range

Given :MdLinkConvertSingle and :MdLinkConvertAll, a command :MdLinkConvert that converts a (selected) range presents itself.

MdLinkConvertAll gives E65 error

calling :MdLinkConvertAll on

[unix](https://unix.stackexchange.com/questions/39623/trap-err-and-echoing-the-error-line/522815#522815)
 
 
command! -buffer -range=% -bar TagLinks silent keeppatterns <line1>,<line2>substitute#\v%(\[[^\]]+\]\(\s*)@<!\zs<https?://([^.]+)\S+#[\1](\0)#giep

causes

Trovato errore eseguendo function mdlink#ConvertAllLinks[1]..mdlink#ConvertRange[32]..mdlink#ParseLineInBodyFor:
riga   24:
E65: Riferimento all'indietro non consentito

gitcommit adaption

For what it's worth (maybe put it in a wiki?), here's an adaption to gitcommit messages, moving the links into a link section before any other comments on writing the buffer:

autocmd BufWrite <buffer>
            \ TagLinks |
            \ call mdlink#ConvertAllLinks() |
            \ call PutLinksBeforeComments()

command! -buffer -range=% -bar TagLinks silent keeppatterns <line1>,<line2>substitute#\v%(\[[^\]]+\]\(\s*)@<!\zs<https?://(%([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})#[\1](\0)#giep

" needs to be :sourced only once per session.
silent! function PutLinksBeforeComments()
    mark `
    normal! gg
    let hash_start = search('^#', 'nW')
    if hash_start == 0 || getline(hash_start) ==? '## Links'
        return
    endif

    let links_start = search('^## Links$', 'nW')
    if links_start == 0
        return
    endif

    let move_start = links_start
    call append(line('$'), '')
    let move_end = line('$')

    keepjumps execute move_start . ',' . move_end . 'move ' . (hash_start - 1)
    normal! g``

    let l:last_non_blank_line = prevnonblank(line('$'))
    if l:last_non_blank_line < line('$')
        execute (l:last_non_blank_line + 1) . ',$delete'
    endif
endfunction

Add command to renumber labels

The labels in the document body and in the reference section should be in order.

The following Markdown document

# Notes

[Vim][1] is an text editor.
[Neovim][0] is another one.

## Links

[0]: https://neovim.io/
[1]: https://www.vim.org/

should be converted to

# Notes

[Vim][0] is an text editor.
[Neovim][1] is another one.

## Links

[0]: https://www.vim.org/
[1]: https://neovim.io/

Adapt to email?

Hi! This is a brilliant idea. For those of us who write emails with nvim, it'd be great to have a similar thing which got urls out of the way and down to a References section. I have tried with some macros, but your solution is much more elegant. I wish I could program in order to extend it for email!! :)

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.