Step 9 of 10

19. The Global Command

Collapsing bullet points

I take all of my notes in Vim, because nothing else allows me to write so quickly. Most of my notes are in plaintext/markdown. I use a particularly small font size, so I like to hard-wrap my text (adding newlines at around the 80-character mark), because it means I can avoid worrying about formatting and keep everything 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 ‘move up a line and join it with the one below’. The result is that every line which isn’t the start of a new bullet point gets joined onto the line before it.

Work through the checklist below. Visually select the bullet points first to restrict the inverse global command to that range, then flatten them. When you press : with a selection active, Vim fills in the '<,'> range for you — you only type the command that comes after it.

  1. Select all of the bullet points with ggVG Grab all of your notes in a linewise selection first — press ggVG.
  2. Flatten the wrapped lines with :v/\v^\s*-/-j With the selection active, press : and type v/\v^\s*-/-j, then hit Enter.
Select all of the bullet points with ggVG Grab all of your notes in a linewise selection first — press ggVG.

Next: Flatten the wrapped lines with :v/\v^\s*-/-j

Loading editor…