I want to underline a word in Vim. How can I do this?
After closing the file and reopening it that word should still be underlined.
I want to underline a word in Vim. How can I do this?
After closing the file and reopening it that word should still be underlined.
Bearing in mind that Vim is a (some might say the) text editor and not a word processor, there are two ways this can be addressed.
Assuming that you want to edit the text file to underline a heading or similar. You can do this by duplicating the line using yy]p (or :t .<CR>
) and replacing the text with hyphens with a :substitute
command like :s!\S!-!g
.
Of course you will need to :write
this file to preserve these.
Alternatively, you can use the :match
functionality to underline the text in your editor without touching the file:
:match Underlined /someword\|otherword/
You would need to add this to a startup script (such as vimrc
) to persist this formatting.
See :help :match
in Vim for more information.
filetype
or syntax
plugin. (See :help plugin
in Vim). As a hack you could add it to your .vimrc
(or _vimrc
on Windows).
May 22, 2010 at 7:39
:match /_[^_]\{-}_/
(untested)
May 24, 2010 at 4:53
<C-k>'-
result: ‾
Though still using two lines.
Jan 19, 2017 at 12:58
There is an article Underline using dashes automatically that describes one way to underline when writing plain text files.
<C-k>'-
result: ‾
Though still using two lines.
Jan 19, 2017 at 12:58