← All lessons

19. The Global Command

Step 9 of 10

Collapsing bullet points

I take all of my notes in Vim, because nothing else allows me to write so quickly. Most of my notes in plaintext/markdown. I use a particularly small font size, so I like to hard-wrap my text (, because it means I can avoid worrying about formatting and just get the information I want on the page. adding newlines at around the 80-character mark) so that I can keep it readable without having to shift my eyes around all over the screen.

For me, I love nested bullet points. There’s an example of what my notes look like in the editor.

If I’m sending these notes to someone, or if I want to copy-paste to Notion or something, the hard-wrapping causes problems. You end up pasting the newlines, which can result in awkward formatting in certain tools.

We can use the global command to ‘flatten’ the bullet points so that they are all on the same line.

:v/\v^\s*-/-j            (flatten hard-wrapped bullet points onto a single line)

Now that’s cryptic! Bear with me.

This is the inverse global command — :v. The regular expression here matches lines whose first non-whitespace character is a dash, so the :vglobal command is going to match all of the lines whose first non-whitespace character is not a dash. The /-j part is saying ‘join this line onto the previous line’. The result is that all of the lines that aren’t a new bullet point are joined into the line before. Give it a go!

Give that command a try in the editor.

Loading editor…