[neomutt-devel] Vim: The magic of conceal

Richard Russon rich at flatcap.org
Thu Nov 16 19:14:34 CET 2017


Vim has a highlighting mode that can conceal text.
I find it quite useful when looking at code.

All the functions in libmutt now have consistent names, like
mutt_file_safe_rename().  Here's some vim script to simply the names:

" Match just the leading 'mutt_'
syntax match mutt_lib_conceal "\vmutt_\ze(b64|date|file|hash|list|map|mb|md5|mem|sha1|str)_\i+>" conceal
" Match the entire function name
syntax match mutt_lib_highlight "\vmutt_(b64|date|file|hash|list|map|mb|md5|mem|sha1|str)_\i+" contains=mutt_lib_conceal

" Add some colour
highlight mutt_lib_conceal ctermfg=121 guifg=#60ff60 guibg=#303030
highlight link mutt_lib_highlight mutt_lib_conceal

" Enable conceal
set conceallevel=2
" Toggle conceal
nmap <silent> <F1> :let &conceallevel=2-&conceallevel<CR>


Now, all the library functions will be coloured and abbreviated.
And toggled at the flick of a switch (F1).

Before:
    new_last_folder = mutt_str_strdup(Context->path);

After:
    new_last_folder = str_strdup(Context->path);


Of course if colour isn't your thing, you can use an icon instead.
Change the conceal line to add a 'cchar' and colour it.

syntax match mutt_lib_conceal "\vmutt_\ze(b64|date|file|hash|list|map|mb|md5|mem|sha1|str)_\i+>" conceal cchar=✉
highlight Conceal ctermfg=99 guifg=#6060ff


Icon'd:
    new_last_folder = ✉str_strdup(Context->path);


To make this automatic, you'll need an 'autocmd' in your vimrc:

autocmd BufNewFile,BufReadPost *.[ch] source conceal.vim


Here's something I use to conceal: 'const', 'enum', 'struct', 'unsigned', 'static'
When scanning large blocks of code, I don't if something is 'const' or
'unsigned.  If I see an 'Address', I know it's a struct.

" Reset some standard definitions
syntax clear cStorageClass
syntax clear cStructure

" Redefine a definition, minus the ones we want to conceal
syntax clear cType
syntax keyword cType _Bool u_int32_t uintptr_t uint64_t complex uint_least8_t clock_t imaginary mbstate_t int_least64_t int8_t time_t DIR int wchar_t uint8_t
syntax keyword cType int_fast8_t int_least8_t ssize_t u_int16_t long uint16_t uint_fast64_t FILE uint_least64_t int_fast16_t int_least16_t int64_t ldiv_t
syntax keyword cType uint32_t u_int8_t double intmax_t off_t _Complex int_fast32_t uint_fast8_t int_least32_t void wint_t char16_t u_int64_t
syntax keyword cType uint_fast16_t fpos_t wctrans_t jmp_buf uintmax_t _Imaginary size_t uint_least16_t sig_atomic_t wctype_t char char32_t int16_t uint_fast32_t
syntax keyword cType int_fast64_t ptrdiff_t uint_least32_t int32_t float va_list intptr_t div_t bool short signed

" Conceal some keywords
syntax match mutt_conceal "\<const "    conceal containedin=cCppInElse2,cCppOutIf2
syntax match mutt_conceal "\<enum "     conceal containedin=cCppInElse2,cCppOutIf2
syntax match mutt_conceal "\<struct "   conceal containedin=cCppInElse2,cCppOutIf2
syntax match mutt_conceal "\<unsigned " conceal containedin=cCppInElse2,cCppOutIf2
syntax match mutt_conceal "^static "    conceal containedin=cCppInElse2,cCppOutIf2


What crazy things do *you* do with vim?

Cheers,
    Rich / FlatCap
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mailman.neomutt.org/pipermail/neomutt-devel-neomutt.org/attachments/20171116/08cf10cd/attachment.sig>


More information about the neomutt-devel mailing list