Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make words invisible in vim?

Tags:

vim

In vimwiki, I can input a link like this:

[[link]]

When I put cursor on the line, [[]] is visible:

>[[http://www.google.com/]]<

When the cursor is moved away, [[]] is invisible:

>http://www.google.com/<

I notice this behavior in vim's help manual(:help vim): *vim:*(*s are invisible until I type V).

I cannot figure out how it works. Thanks for your help.

like image 386
kev Avatar asked Apr 30 '12 12:04

kev


2 Answers

This is a feature called "conceal" that was added in vim 7.3 (if I recall correctly). For a simple example, try this.

Open a buffer and type three lines, the middle one being "foobarbaz". Then enter the following ex commands:

set conceallevel=2
syntax match Todo /bar/ conceal

When your cursor is on the "foobarbaz" line, "bar" will be visible (and highlighted with the Todo highlight group if you have syntax highlighting on). Once you move off the line, "bar" will disappear.

For more information see :help conceal and :help conceallevel.

like image 116
Randy Morris Avatar answered Sep 28 '22 01:09

Randy Morris


I think that hiding text can be a very helpful feature. Think about text folding or readability of links.

To hide text Vim 7.3 has introduced the "conceal" argument. Hiding text is a well defined Vim feature. It is not a dirty trick. See

 :help :syn-conceal 
 :help 'conceallevel' 
 :help 'concealcursor'

Please note that conceal works only for syntax regions, not for matches.

I have no experience with conceal, so I can't provide an example out of the box.

Habi

like image 27
Habi Avatar answered Sep 28 '22 02:09

Habi