The other day I found myself copy-pasting some Google Docs texts into a new Jekyll website, and so I had to format quite a bunch of lists. After Google Docs, the reflex was to select the rows, and hit ⌘+Shift+8, so I thought: Hey why not make a key-mapping? 🤓

I’ve tried this kind of thing before and I new it’s hard to get the ⌘+Shift- key mappings, so I went with what I knew worked, so I decided on Alt-8 instead.

Here is what came out:

vnoremap <buffer> ¶ :s/^\s*/\0* /g\|:nohlsearch<CR>

So it’s a visual map: it’ll work on a selection of lines. I know some Vim veterans disregard visual mode as not hard-core enough, and recommend using text objects instead, but visual mode seems to work quite well for me so far. 😉

It’s a <buffer> mapping, so that it’s only set for the current buffer, and it can do something else in buffers of other types.

It’a noremap just to be safe: if any of the mapped key-strokes are mapped to something else by some other module, I don’t want them to interfere.

The thingy is what comes out when you type Alt-7 on a Mac. ¯_ツ_¯

Of course (!) one can’t figure out the bulleted lists without also thinking about the numbered ones, so I though Alt-8 would be a perfectly natural next step. 🙂

Here it comes:

vnoremap <buffer> • :s/^\s*/\00 /g\|:nohlsearch\|:normal gpo^g<CR>

Neat! 🤓

* * *

P.S.: As is often the case, writing this quick article exposed a glitch in the last key-binding, and a hole in my understanding of how this whole thing works: I thought I needed <C-U> at the beginning, and while checking again the docs I found I actually don’t. Cool! 🤓