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.

link|improve this question
feedback

migrated from stackoverflow.com May 23 '10 at 19:15

This question came from our site for professional and enthusiast programmers.

2 Answers

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.

The first is 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 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:

:match Underlined /someword\|otherword/

See :help :match in Vim for more information.

link|improve this answer
it's ok .... after close and reopen the word is not underlined – ungalnanban May 22 '10 at 7:30
You could add the match command to a filetype or syntax plugin. (See :help plugin in Vim). As a hack you could add it to your .vimrc (or _vimrc on Windows). – Johnsyweb May 22 '10 at 7:39
2  
The :match command given is limited to underlining specific words that you define in the match command. A more general purpose method might be to match words that are written between underscores. For example, any word or phrase written between two underscores would be underlined by the command: ":match /_.*_/" Again, you would have to put the command in .vimrc (or somewhere else) to have it always work in all your files. Also, the particular example given using underscores may not be perfect, but it illustrates the idea. – Herbert Sitz May 23 '10 at 19:51
@Herbert: Good idea. A non-greedy match might be more useful, though. Something like :match /_[^_]\{-}_/ (untested) – Johnsyweb May 24 '10 at 4:53
feedback

There is an article Underline using dashes automatically that describes one way to underline when writing plain text files.

link|improve this answer
1  
It's underlining hole line. I don't want to underline hole line eg: this is sample line // underline sample only – ungalnanban May 22 '10 at 7:24
feedback

Your Answer

 
or
required, but never shown