Vim Tips: Writing ASCII lines quickly
I sometimes need to write an ASCII line (hr) quickly, like ----------, here
are two ways I do it in Vim.
I sometimes will separate blocks of code with a comment like:
// ---------------------------------------------------------------------------
To do that quickly in Vim, I will press:
ito enter Insert Mode/,/,spaceto type out//Escto exit Insert ModeA,-,Escappend-to the end of the line, 75 times
You can also use o instead of A to use this trick with lines instead of
characters, i.e. 5o- [ ] task, Esc would use o 5 times to write a new
line below the cursor with - [ ] task.
When I want the line to be exactly as wide as the line above/below, like with a Markdown header or table:
Header
======
Here, when I have my cursor on the “Header” line, I press:
yypyank and paste the line belowjmove down to the newly pasted “Header” lineVvisually select the entire 2nd “Header” linerreplace the entire line with…=the=character
I’ll also use this with Markdown tables, and do something like:
| Num | Header 1 | Another Long Cell |
yypjVr-copy and paste the header row, move down to it, visually select the new line, replace with all-characterskmove back up to the header row0move the cursor all the way leftjmove back down to the first-r|replace with a|characterlmove right one character to the 2nd-r<space>replace with a single ` ` characterkmove back up to header rowf|move to next|character
From here, I’ll rinse and repeat until the table looks like:
| Num | Header 1 | Another Long Cell |
| --- | -------- | ----------------- |
Happy lining!