WS-Na / vim-searchconceal

Hide searches and patterns using vim's conceal feature

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

This Vim plugin lets you hide patterns of a buffer's content without modification, using Vim's conceal feature.

Use

Imagine you have a file, full of uninteresting tags and text:

Example screenshot

This plugin lets you hide distracting text:

  1. 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).
  2. All matches are concealed with an "a".
  3. Maybe you find "Id" too redundant. Type :SearchConceal b Id (or some other regular expression)
  4. The second match is concealed with a "b".
  5. A third concealed pattern uses "c", 4th "d", 5th, "e", etc

Example screenshot

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 <[^>]*>):

Example screenshot

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

Commands

: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.

Installation

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}

About

Hide searches and patterns using vim's conceal feature


Languages

Language:Vim Script 100.0%