Vim Tips Wiki
(tweaks, see also; comment that another tip may need to be merged)
No edit summary
Line 55: Line 55:
 
{{todo}}
 
{{todo}}
 
*Decide what to do with new tip [[Underline text]]. Perhaps it should be merged to here? [[User:JohnBeckett|JohnBeckett]] 04:57, August 9, 2011 (UTC)
 
*Decide what to do with new tip [[Underline text]]. Perhaps it should be merged to here? [[User:JohnBeckett|JohnBeckett]] 04:57, August 9, 2011 (UTC)
  +
  +
----
  +
  +
<code>yypVr-</code> also works well. Great tip for Markdown and WikiTex users.
  +
  +
[[User:Linktohack|Linktohack]] 15:37, February 3, 2012 (UTC)

Revision as of 15:37, 3 February 2012

Tip 750 Printable Monobook Previous Next

created 2004 · complexity intermediate · author Chris X Edwards · version 6.0


This tip shows how to underline text document headings with, for example, a dashed line.

Using a mapping

Starting with a line of text like:

A Very Important Tip!

the mapping below inserts a row of dashes like this:

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

This is useful to highlight headings. Add the following to your vimrc:

" Underline the current line with dashes in normal mode
nnoremap <F5> yyp<c-v>$r-

" Underline the current line with dashes in insert mode
inoremap <F5> <Esc>yyp<c-v>$r-A

Of course you can use other characters instead of -, for example, = or _.

In case you want to get a line above and below the heading, do this in normal mode:

<F5>yykP

Using substitute

You can use the global and substitute commands (:help :g, :help :s) to underline all headings matching a pattern. For example, the following adds a row of dashes under each line that starts with "Chapter":

:g/^Chapter/t.|s/./-/g

It works by finding each matching line, then copying it (:help :t), then substituting each character (.) in the line.

See also

Comments

 TO DO 


yypVr- also works well. Great tip for Markdown and WikiTex users.

Linktohack 15:37, February 3, 2012 (UTC)