I have a command mapping ("ESC-P") in my .vimrc which underlines the current line, leaving whitespace or # intact.
map ^[p :.t.^M:s/[^[:space:]#]/-/g^M
If I run this on a line of text, it nicely underlines it.
this is a test line ---- -- - ---- ---- Likewise, it works nicely on comments:
# this is a test comment # ---- -- - ---- ------- But it I have any other hashtags in the line, they're also left alone. I'd like to replace them all EXCEPT for one that occurs at the start of a line.
For instance, I get:
# # # ## # This is a messy comment # # # ## # ---- -- - ----- ------- this has a hashtag # here ---- --- - ------- # ---- But what I'd like to get is this:
# # # ## # This is a messy comment # - - -- - ---- -- - ----- ------- this has a hashtag # here ---- --- - ------- - ---- I've spent some time on this and can't come up with a clean way to match all whitespace plus a # only in the first column.
Any ideas?
(As an aside, anyone know why \s or [:s:] don't work properly inside of a character class in vim? Only [:space:] works here.)