I would like Vim to show 'virtual' characters instead of real
characters. For example, I want Vim to show 'password=******'
instead of the actual password when editing a file, but without
modifying the password content. For example, when folding, vim
does this. It replaces the whole block with a 'virtual' line
that is not really in the file. How does Vim do this?

It sounds like you're trying to do two diff. things. One would be described as "vertical folding". There's an unofficial patch floating around that does it...you can learn more (and download the patch) from

http://vince.negri.googlepages.com/concealownsyntaxforvim

However, if you're just looking for a way to hide passwords, you might try exploiting syntax highlighting to make the text foreground and background the same color.

hi Password ctermfg=red ctermbg=red cterm=NONE guifg=red guibg=red

followed by

match Password /password\s*=\s*\zs.*/

(adjust colors to taste...you may or may not want to see something that would give away the password-length, so you might prefer to use your default background color for the Password group. Using asterisks would give away the length, so it may not matter to you)

It doesn't quite handle some oddball cases such as when you're visually selecting the line, or when the cursor is on the password (where you'll see the character under the cursor), if you have 'hls' set and your search matches something in the password, or possibly when folded. I'm sure there are other instances where it might give you a little grief, but it's a good first-pass attempt to hide passwords. :)

-tim


Reply via email to