I use Vim version 8.2.4919 without 3rd party plug-ins on Ubuntu 22.04.2 LTS running via WSL2.
I want to have italic syntax highlighting for words encapsulated in underscores in comments of my cpp files.
Following is the content of my
.vimrc that does that:
"italic syntax highlighting
autocmd FileType cpp,hpp syntax match Italic "\v<_[a-zA-Z0-9_]*_>" containedin=cComment,cCommentL contained
autocmd FileType cpp,hpp syntax match ConcealUnderscore /_/ containedin=Italic contained conceal
highlight Italic cterm=italic gui=italic ctermfg=lightcyan guifg=lightcyan
This works fine as long as I open my cpp/hpp files from terminal.
But as soon as I open a directory with vim and use netrw (v171) to open a source file, the underscores don't get concealed.
Opened from terminal:
Opened from netrw:
What changes do I need to do to my
cpp.vim to conceal underscores when opening files from netrw?
I already tried:
- Creating a
~/.vim/syntax/cpp.vimand doing the highlighting there (I will use this file instead of
autocmd BufReadPost * syntax match ConcealUnderscore /_/ containedin=Italic contained conceal
autocmd BufEnter * if &ft == 'cpp' || &ft == 'hpp' | syntax match ConcealUnderscore /_/ containedin=Italic contained conceal | endif
autocmd BufReadPost * :syntax sync fromstart
I expected: underscores to be concealed when opening files from netrw