Skip to main content
Became Hot Network Question
deleted 4 characters in body; edited title
Source Link

vim Vim syntax highlighting: conceal does not work when opening files from netrw

I use VIMVim 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 setlocal conceallevel=2 setlocal concealcursor=nc 

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 terminal

Opened from netrw:

opened from netrw

What changes do I need to do to my .vimrc/cpp.vim to conceal underscores when opening files from netrw?

I already tried:

  • Creating a ~/.vim/syntax/cpp.vim and doing the highlighting there (I will use this file instead of .vimrc if possible)
  • 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

vim syntax highlighting: conceal does not work when opening files from netrw

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 setlocal conceallevel=2 setlocal concealcursor=nc 

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 terminal

Opened from netrw:

opened from netrw

What changes do I need to do to my .vimrc/cpp.vim to conceal underscores when opening files from netrw?

I already tried:

  • Creating a ~/.vim/syntax/cpp.vim and doing the highlighting there (I will use this file instead of .vimrc if possible)
  • 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

Vim syntax highlighting: conceal does not work when opening files from netrw

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 setlocal conceallevel=2 setlocal concealcursor=nc 

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 terminal

Opened from netrw:

opened from netrw

What changes do I need to do to my .vimrc/cpp.vim to conceal underscores when opening files from netrw?

I already tried:

  • Creating a ~/.vim/syntax/cpp.vim and doing the highlighting there (I will use this file instead of .vimrc if possible)
  • 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

Source Link

vim syntax highlighting: conceal does not work when opening files from netrw

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 setlocal conceallevel=2 setlocal concealcursor=nc 

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 terminal

Opened from netrw:

opened from netrw

What changes do I need to do to my .vimrc/cpp.vim to conceal underscores when opening files from netrw?

I already tried:

  • Creating a ~/.vim/syntax/cpp.vim and doing the highlighting there (I will use this file instead of .vimrc if possible)
  • 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