Is there a nice quick way to have a text line underlined with dashes (exact same length)? For purpose of rst documents (sub)*sections have to have single character underlings of the same length as previous. So section heading should look like
In this section main character dies
-----------------------------------
My current approach is to look at the position of cursor (when I'm at the end of the line) and then: o{N}I-
where {N}
is the cursors position. I'd much rather have some nice macro to do it with custom character.
Copy the line with Y
, paste it with p
, and replace everything with -
using Vr-
(select the line, replace character by -
).
So:
YpVr-
Note: This assumes you don't have the somewhat common Y
-> y$
mapping. If you do, use yy
instead of Y
.
If you want a (crude) mapping to do this a bit faster, you could use something like:
:nnoremap <leader>u YpVr
then typing \u-
(assuming you haven't changed the leader key) would underline a line with -
.
I think you might like the extline plugin: https://github.com/drmikehenry/vim-extline
It was designed for to work with reStructuredText documents, and I've been using it for years (actually for more years than it's been available as a plugin, since I've been using Dr. Mike's configuration for quite some time now).
With it you can start the line by typing the character you want and typing Ctrl+L Ctrl+L. Or use one of the other available shortcuts:
The following mappings apply in Visual and Insert modes (but, notably, NOT in
Normal mode):
CTRL-L CTRL-L Auto-line update
CTRL-L CTRL-H Horizontal line update
CTRL-L CTRL-U Change to underlined title
CTRL-L CTRL-O Change to overlined title
CTRL-L CTRL-I Change to underlined and overlined title
CTRL-L = Force Section heading (level 1)
CTRL-L 1
CTRL-L - Force Subsection heading (level 2)
CTRL-L 2
CTRL-L ^ Force Subsubsection heading (level 3)
CTRL-L 3
CTRL-L " Force Paragraph heading (level 4)
CTRL-L 4
CTRL-L ' Force level 5 heading (level 5)
CTRL-L 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With