Censor blocks specified patterns from view: they're in the buffer, and you can see they're there, but you can't read them.
Instead of "camouflaging" them by making them the same color as the
background, it uses vim's conceal
feature to intercept the characters at
render time: When words are censored, they won't be displayed on the terminal
at all, even when the cursor is on them.
Note that the buffer is never changed: the underlying text is the same regardless of whether or not censor is enabled.
Use your favorite plugin manager.
- Add
Plug 'shayneholmes/vim-censor'
to .vimrc - Run
:PlugInstall
Toggle censor on and off.
You can easily map a keypress to it:
nnoremap <Leader>c :Censor<CR>
Turn censor off.
Ready-made recipes for interesting censorship patterns:
" Censor word characters: letters, numbers, and _ (default)
"
" Foo bar, hash. βββ βββ, ββββ.
" Baz (quux)? -> βββ (ββββ)?
" Hashbaz! βββββββ!
"
let g:censor_pattern='\w\+'
" Show the first and last character of every word
"
" Foo bar, hash. Fβo bβr, hββh.
" Haz (quux)? -> bβz (qββx)?
" Hashbaz! hβββββz!
"
let g:censor_pattern='\w\zs\w\+\ze\w'
" Censor all non-whitespace characters
"
" Foo bar, hash. βββ βββββ βββββ
" Baz (quux)? -> βββ βββββββ
" Hashbaz! ββββββββ
"
let g:censor_pattern='\S\+'
" Censor words and the whitespace gaps between them
"
" Foo bar, hash. βββββββββββββββ
" Baz (quux)? -> βββββββββββ
" Hashbaz! ββββββββ
"
let g:censor_pattern='\v\S+%(\s+\S+)*'
Options don't immediately take effect: If you change an option while censor is on, you'll need to turn censor off and on again to see any change.
Options can be configured for an individual window or buffer by prefixing them
with w:
or b:
instead of g:
.
A regular expression that specifies what should be censored. It is always
interpreted as though 'magic'
is set; see :help :syn-pattern
.
Change this to get different censoring behavior; see Recipes, above.
The character that will be used in place of obscured characters. If not
specified, the default conceal character in listchars
will be used. (By
default, this is the space character.)
" Use the letter 'X' to replace censored characters
let g:censor_replacement_char = 'X'
See :help :syn-cchar
.
Modes in which the cursor's current line will be censored.
By default, censored items in the current line remain censored, even when you're in insert mode. However, there are alternatives:
" Show censored items in the curre
6F49
nt line when inserting and in visual mode
let g:censor_concealcursor='nc'
" Always show censored items in the current line
let g:censor_concealcursor=''
See vim's concealcursor
for details.
An optional definition of highlighting for censored characters. Changes the
highlighting of the Conceal
group; see help hl-Conceal
. The original value
will be restored when censor is disabled.
" Remove highlighting entirely
let g:censor_highlight_def = NONE
Note that highlighting is global and so can't be altered per buffer.
If you want to run additional commands when toggling censoring, you can do
this with the CensorEnter
and CensorLeave
events:
CensorEnter
runs just after enabling censoringCensorLeave
runs just before disabling censoring
This pattern is similar to e.g. TabEnter
and TabLeave
.
Some examples:
# Show the cursor column when censored
autocmd! User CensorEnter setl cursorcolumn
autocmd! User CensorLeave set cursorcolumn<
# Get fancy: Show capitals vs lower-case
function! s:censor_enter()
syn match CensoredChar '[a-z]' conceal cchar=x
syn match CensoredChar '[A-Z]' conceal cchar=X
endfunction
autocmd! User CensorEnter call <SID>censor_enter()