Is there a way to hide all text that is being entered, just as passwords are hidden? so that the cursor moves but the output is æquivalent to spaces, until the function is turned off? Variants of this function might leave the letter or word under the cursor visible.
In Insert mode, we can intercept each inserted character, and replace it with a
*. Here is a quick proof of concept:
autocmd InsertCharPre * let v:char='*'
But that one-liner is undesirable, because now it's difficult to turn off that autocommand. You need to restart your Vim to get back to normal!
The tidy way:
augroup MyPassListener autocmd! autocmd InsertCharPre * if s:RecordCharacter(v:char) | let v:char='*' | endif augroup END
You will need to implement your own RecordCharacter function, and perhaps build up a secret string:
let s:pass = "" function! s:RecordCharacter(c) let s:pass .= c " Maybe do something special here if the character is a carriage return return 1 endfunction
When you are finished, and want to go back to normal, clear the event listener group you defined:
augroup MyPassListener autocmd! augroup END
Notably the technique above won't store the typed characters in the buffer. A load of
*s will be added to the buffer instead. The secret characters will be available only in the
If you want the characters that were typed to exist in the buffer, you will need to hide them, rather than replace them. Two possible options are:
Set the foreground and background highlighting to the same colour. This should make the text invisible (provided the characters are not highlighted in bold, which can render differently in terminals). (There might also be issues when the cursor is hovering over a character.)
concealfeature to hide or overlay the characters in the buffer.