This Vim plugin lets you hide patterns of a buffer's content without modification, using Vim's conceal feature.
Imagine you have a file, full of uninteresting tags and text:
This plugin lets you hide distracting text:
- Don't want to see "dependency"? You can search for
/dependency
, and then type:SearchConceal
to conceal all the matches (by default the:SearchConceal
command uses the pattern in the@/
register). - All matches are concealed with an "a".
- Maybe you find "Id" too redundant. Type
:SearchConceal b Id
(or some other regular expression) - The second match is concealed with a "b".
- A third concealed pattern uses "c", 4th "d", 5th, "e", etc
Using regular expressions lets you hide arbitrary patterns. For example, hiding the content of all tags with /<[^>]*>
and the command
:SearchConceal
(or maybe as a one liner in a script :SearchConceal a <[^>]*>
):
You might add this to your ~/.vim/after/syntax/xml.vim
to apply the setting
to all your xml files.
When you want to see everything again, type :SearchConcealClear
.
Personally, I use this for ad-hoc hiding, and also to hide some syntax in java.
My ~/.vim/syntax/after/java.vim
file is configured to show Some<Generic>
as
Some<~>
to cut down on the visual clutter:
SearchConceal ~ <[A-z<>,\ ]\+> ms=s+1,me=e-1
:SearchConceal
Conceal the current pattern in @/
with 'a' (or 'b', 'c', etc for each subsequent
call to :SearchConceal
)
:SearchConceal char
Conceal the current pattern in @/
with char
. If char is more than one
character, then the pattern is concealed altogether (syntax match
doesn't
support conceal with cchar > 1 characters anyway!)
:SearchConceal char pattern
Conceal the regular expression pattern
with char
:SearchConceal char pattern syn-pattern-offset
Conceal the regular expression pattern
with char
, and apply any syntax
matching offset settings from syn-pattern-offset. Note that this plugin uses syntax match
so ms
and me
are the only options that are relevant to this command.
:SearchConcealClear
Clears all syntax definitions created by this plugin, un-hiding any concealed text.
Use your favorite plugin manager to install the vim-searchconceal.
Vundle:
Plugin 'dsummersl/vim-searchconceal'
" Add mappings if desired:
map <leader>ch :SearchConceal<CR>
map <leader>cc :SearchConcealClear<CR>
Packer:
use {'dsummersl/vim-searchconceal', config = function()
vim.cmd([[
" Conceal the latest search
map ,cc :SearchConcealClear<CR>
map ,ch :SearchConceal<CR>
])
end}