Reputation: 62528
Now, this may be something obvious and already solved and known to everyone, but I just thought of it, so have mercy ...
Is there a Vim plugin for (when writing markdown texts) that enables you to insert links in a way that Ctrl-L in here (StackOverflow) does it. Or something similar to it.
For example, I write in a link, http://www.google.com, press Ctrl-L, and it moves that link to the bottom of the page replacing it with [description][28] where 28 is the current (increase by one from last) identifier.
Anyone? Anything similar?
Upvotes: 5
Views: 1358
Reputation: 1
In regard to Dennis Wegners answer and his .vimrc
entry for <leader>4
this worked for me:
nnoremap <leader>4 ciw[<C-r>"](<Esc>"*pa)<Esc><CR>
vnoremap <leader>4 c[<C-r>"](<Esc>"*pa)<Esc><CR>
"*pil
resulted in not writing the closing )
but with "*pa
it works.
Upvotes: 0
Reputation: 1
:help autocmd
can be used to list the possible options.
it may not do exactly what you asking for but you can change it to your needs.
autocmd Filetype markdown,rmd noremap ,1 i[][]<Esc>bplla1<esc>m1Go[1]:<Space><esc>p'1f1wa<Space>
autocmd Filetype markdown,rmd noremap ,2 i[][]<Esc>bplla2<esc>m2Go[2]:<Space><esc>p'2f2wa<Space>
where 1
may be the first link and 2
the second...
put your link into the primary selection.
position your cursor in normal mode and hit ,1
to begin.
Upvotes: 0
Reputation: 91
I use a custom macro to insert links from the system clipboard (Tested with Vim 7.3 on OS X and Windows, should work with Linux, too) and use formd to convert the resulting inline-style links to reference-style when I see fit.
I got these macros in my .vimrc
:
" Create a Markdown-link structure for the current word or visual selection with
" leader 3. Paste in the URL later. Or use leader 4 to insert the current
" system clipboard as an URL.
nnoremap <Leader>3 ciw[<C-r>"]()<Esc>
vnoremap <Leader>3 c[<C-r>"]()<Esc>
nnoremap <Leader>4 ciw[<C-r>"](<Esc>"*pli)<Esc>
vnoremap <Leader>4 c[<C-r>"](<Esc>"*pli)<Esc>
And use these to invoke formd
which lives in my ~/bin/
folder:
" Use formd to transfer markdown from inline to reference links and vice versa
" see: http://drbunsen.github.com/formd/
nmap <leader>fr :%! ~/bin/formd -r<CR>
nmap <leader>fi :%! ~/bin/formd -i<CR>
So, I just copy the needed link, navigate to the word (or use visual mode to select more words) to turn into a link and hit ,4
. If I know I'll link a word or selection but don't have the URL yet, I hit ,3
and the macro inserts the needed parentheses empty.
Hitting ,fr
produces the reference-style. If needed, ,fi
returns to inline-style links.
Upvotes: 6
Reputation: 3207
I do not have an exact matching solution, but my vim-googurl plugin does part of the job.
Upvotes: 1
Reputation: 40927
While it's not the exact workflow you described this plugin seems like it is designed for making footnotes easier to work with.
Upvotes: 0