Swopped out work laptops earlier this year, and for reasons involving ignorance ("back up your dotfiles to GitHub" means as much to me as it does to Emily Fusselman's rabbit) and laziness I have not had the advantage of my fully functioning battle station set of tweaks for some months now. Over the past few days, though, I've had a felt need for some new functionality, and, having achieved this, I took on an old challenge I had never quite cracked.
I shall treat of these in turn.
I've been doing a lot more in Markdown lately, and while taking notes during a training on returning to office work in a COVID-19 environment1 I realized that, for note-taking purposes and later reference, Markdown's reference links make lots more sense for a readable document than in-line HTML-style links.
Per the documentation, inline links look like:
This is an [example in-line link](https://examplelink.org) in a sentence people are trying to read
Reference links look like:
This is the [first example reference link][1] and this is the [second example reference link][2].
[1]: https://examplelink.org
[2]: https://secondexamplelink.org
It's more readable! I like that. I like to read. :) So I wanted to figure out how to make it faster and easier. You may remember that my old link-adding techniques looked like:
Add Link to Word the Cursor Is On
" make the word under the cursor a hyperlink to URL from system clipboard
" 18jan2016
" mapping <leader>a to:
" select the current word with viw
" wrap the current word in an <a href> tag
" by moving to the end of the word and adding <a> to close the tag
" then moving to the beginning of the WORD and adding <a href="">
" moving back to the beginning of the WORD to move to the quotes
" and populate the quotes with the contents of the + register
" mostly inspired by Steve Losh
" edited 27dec2016
" :nnoremap <leader>a viw<esc>a</a><esc>Bi<a href=""><esc>Bci"<esc>a<c-r>+<esc>
:nnoremap <leader>a viw<esc>a</a>
Add Link to Last Thing That Was Visually Selected
" make the last visually selected text a hyperlink to URL from system clipboard
" 18jan2016
" mapping <leader>v to:
" select the last visual selection with `< and `>
" wrap that selection in an <a href> tag
" by moving to the end of the visual selection and adding </a> to close the tag
" then moving to the beginning of the visual selection and adding <a href="">
" moving back to the beginning of the visual selection to move to the quotes
" and populate the quotes with the contents of the + register
" mostly inspired by Steve Losh
:nnoremap <leader>v `>
The needs of the Markdown style of reference link are slightly different, however, so the approach I landed on was the following:
Add Reference Link to Last Thing That Was Visually Selected
" add a reference link in Markdown
:nnoremap <leader>rl <esc>gvI[<esc>A][]<esc>
This will need at some point some editing to append to the bottom of the file and add the actual links, etc., but I'm not quite there yet.
I've also long struggled with automating / streamlining making things bullets in Markdown, as well. The most common use case for making things bullets that weren't bullets as I was originally typing things in involves marking up previously typed things that I've visually selected. Luckily, the modal editor paradigm allows this to work with a subtle change in the mapping: it turns out a person can remap visual mode key combinations just as she can remap normal mode key combinations. Fiddling around with this this week, I landed on:
" add bullet format to visual selection
:vnoremap <leader>- <esc>gv:s/^/ - /<enter>
:vnoremap <leader>* <esc>gv:s/^/ * /<enter><esc>V>
Then, when I started dinking around with consolidating all this, I realized I had this already floating around:
:nnoremap <leader>li I- <esc>
:nnoremap <leader>ld 0V><esc>f-r*
This latter solves the problem that, often, what I need to do automatically is indent an existing bullet...but, obviously I didn't use it enough to remember that I'd created it.
But! As a bonus, I'd always had the problem—particularly when working on my .vimrc file—of wanting, even needing, to comment out a bunch of lines that I'd visually selected. For some reason, this never clicked until recently, when I realized this operation is more or less trivial:
:vnoremap <leader>c <esc>gv:s/^/" /<enter>
I have in the works a way to abstract that key combination to insert comments by filetype (HTML, Python, VimScript) but it's not super pressing, and the mechanics are basically transparent, so I can leave the details as an exercise for the (likely purely hypothetical, at this point) reader.
—Fat, trying to remember to sharpen his saw
1 Shut up, I'm a union steward, taking notes on things bosses say is kind of my thing.
No comments:
Post a Comment