Vim Tips Wiki
m (Underline Using Dashes Automatically moved to Underline using dashes automatically: Page moved by JohnBot to improve title)
(Clean up)
Line 9: Line 9:
 
|rating=26/18
 
|rating=26/18
 
|text=
 
|text=
I have been using this trick for years but only recently figured out how to add the finishing touch. Basically this technique (best executed as a macro) will take a line of text like this:
+
I have been using this trick for years but only recently figured out how to add the finishing touch. Basically this technique (best executed as a macro) will take a line of text like this:
 
A Very Important Tip!!!
 
and change it to two lines like this:
 
A Very Important Tip!!!
 
-----------------------
   
  +
I use this all the time to highlight headings, etc.
   
 
Add this to your .vimrc file:
 
  +
<pre>
A Very Important Tip!!!
 
 
 
 
and change it to two lines like this
 
 
 
 
A Very Important Tip!!!
 
 
-----------------------
 
 
 
 
Of course in a constant width editor font, this looks a lot more worthwhile. I use this all the time to highlight headings, etc.
 
 
 
 
Add this to your .vimrc file:
 
 
 
"cxe- Underline the current line with dashes
 
"cxe- Underline the current line with dashes
 
map &lt;F5&gt; YpVr-
  +
</pre>
   
 
Note that you can use anything you want instead of - (= and _ spring to mind). Also, I put this under F5, but that's 100% arbitrary and the nice thing about Vim is that you can put it where you want it. And a tip for the tip is that if you use this, you can also easily get a line above AND below the target text. Just do this:
map &lt;F5&gt; Yp:s/./-/g^M:let @/=""^M
 
 
&lt;F5&gt;YkP
   
 
 
(Note that ^M's are really returns that you can achieve in Vim with &lt;ctrl-V&gt;&lt;ctrl-M&gt;.
 
 
The strategy is basically to yank the line you're on with Y, then put it (and your cursor) with p onto the next line. Then comes a single line range substitution that searches for any character and replaces it with a -. The part after the return is only needed by those of us who have hlsearch turned on. I f you don't set the search register to nothing (""), then your whole document will light up and you will need to invest in a seeing eye dog. Note that you can use anything you want instead of - (= and _ spring to mind). Also, I put this under F5, but that's 100% arbitrary and the nice thing about Vim is that you can put it where you want it. And a tip for the tip is that if you use this, you can also easily get a line above AND below the target text. Just do this:
 
 
&lt;F5&gt;YkP
 
 
Hope someone can find this helpful. (P.S. typing in this form box is torture! The worst thing about Vim is how useless you feel without it!)
 
 
}}
 
}}
   
 
== Comments ==
 
== Comments ==
Like you I'd been using something similar for a while but only just realised you could let --AT--/ = "" to stop everything being highlighted when hlsearch is on. As a final cleanup clear the command line with
 
 
map &lt;F5&gt; yyp:s/./-/g&lt;RETURN&gt;:let --AT--/ = ""&lt;RETURN&gt;:&lt;RETURN&gt;
 
 
'''Anonymous'''
 
, June 18, 2004 23:53
 
----
 
A more simple method:
 
 
map &lt;F5&gt; YpVr-
 
 
'''Anonymous'''
 
, June 19, 2004 14:43
 
----
 
The mozex plugin (http://mozex.mozdev.org/) lets you edit forms with an arbitrary text editor including, of course, vim.
 
 
'''Anonymous'''
 
, June 20, 2004 21:29
 
----
 
 
This is helpful, but your command doesn't give proper \t (and 'tabstop' value)
 
This is helpful, but your command doesn't give proper \t (and 'tabstop' value)
 
'''Anonymous'''
 
, June 20, 2004 22:04
 
 
----
 
----
A propos mozex: Is there for GUI-Vim an Event to react on when I click to another window, eg back to mozilla? I'd like to auto-write those buffers, it'd be kewl.
 
 
marco.gergele--AT--web.de
 
, July 6, 2004 8:09
 
----
 
FocusLost?
 
 
 
To help with tabs, :map &lt;F5&gt; Yp^v$r-
 
To help with tabs, :map &lt;F5&gt; Yp^v$r-
 
(ignores leading whitespace)
 
(ignores leading whitespace)
 
'''Anonymous'''
 
, November 22, 2004 9:35
 
 
----
 
----
 
... and to also cope with embedded tabs in the heading use
 
... and to also cope with embedded tabs in the heading use
   
 
:map &lt;f5&gt; yyp&lt;c-v&gt;$r-
 
:map &lt;f5&gt; yyp&lt;c-v&gt;$r-
 
'''Anonymous'''
 
, November 3, 2006 15:56
 
 
----
 
----
 
<!-- parsed by vimtips.py in 0.565241 seconds-->
 
<!-- parsed by vimtips.py in 0.565241 seconds-->
  +
[[Category:Automatic Text Insertion]]

Revision as of 12:06, 30 October 2007

Previous TipNext Tip

Tip: #750 - Underline using dashes automatically

Created: June 18, 2004 19:58 Complexity: intermediate Author: Chris X Edwards Version: 5.7 Karma: 26/18 Imported from: Tip#750

I have been using this trick for years but only recently figured out how to add the finishing touch. Basically this technique (best executed as a macro) will take a line of text like this:

A Very Important Tip!!!

and change it to two lines like this:

A Very Important Tip!!!
-----------------------

I use this all the time to highlight headings, etc.

Add this to your .vimrc file:

"cxe- Underline the current line with dashes 
map <F5> YpVr-

Note that you can use anything you want instead of - (= and _ spring to mind). Also, I put this under F5, but that's 100% arbitrary and the nice thing about Vim is that you can put it where you want it. And a tip for the tip is that if you use this, you can also easily get a line above AND below the target text. Just do this:

<F5>YkP

Comments

This is helpful, but your command doesn't give proper \t (and 'tabstop' value)


To help with tabs, :map <F5> Yp^v$r- (ignores leading whitespace)


... and to also cope with embedded tabs in the heading use

map <f5> yyp<c-v>$r-