When I place the cursor on the parenthesis of the below line, the two parenthesis get highlighted in a cyan color. When I place the cursor on the curly braces, however, no highlighting happens.
// cmake example
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
^ ^ ^ ^
| | | |
| +------+--------+ |
| | |
| +--- no highlighting |
| |
+-------------------------+---------------------+
|
+--- expected highlighting works
Note that the set may need to be inside a sub-block to fail (i.e inside an if(SOMETHING) ... endif(SOMETHING)
block for example).
Here is another example with C++ code:
// C++ example
a = "this (string) here"; // this one fails, it's inside a string
a = string("here"); // here the highlight works
As we can see the parenthesis are outside of a string and the curly braces are inside the string.
I have the same problem in comments and various other types of string-like regions.
How do I get this highlighting to work in strings and comments like it was in older versions of Vim?
Here are a couple of screenshots. The vertical bar is the cursor placed just before the parenthesis or curly braces.
Note 1: Yes. The highlighting works just fine with curly braces outside of a string, and also square brackets, <,>
, etc.
Note 2: The %
key works as expected, so I can find the matching character, but that's not as practical as the highlighting.
So far, this has shown up in nearly all the files formats I used (C++, Go, JavaScript, Ruby, CMakeLists.txt, etc.) However, at least the parenthesis and curly braces do work fine in a shell script (sh
).
As for the matched pairs, I have:
matchpairs=(:),{:},[:],<:>
I added the <:>
in my settings, but the problem occurred before I added those and whether I specify matchit
or not:
set matchpairs+=<:>
packadd! matchit
Further, I tried to comment out all of my entries in my ~/.vimrc
and the results are the same.
On my clean install, I see the same issues. I tried to add
matchadd! matchit
let b:match_skip = "0"
to my ~/.vimrc
and that had no effect on the issue.
Just in case, here is the /usr/share/vim/vim80/debian.vim
file that gets loaded through the /etc/vim/vim.vim
(I removed the full line comments to make it shorter):
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
set nocompatible " Use Vim defaults instead of 100% vi compatibility
set backspace=indent,eol,start " more powerful backspacing
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set nomodeline
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
if &term =~ "xterm-debian" || &term =~ "xterm-xfree86"
set t_Co=16
set t_Sf=[3%dm
set t_Sb=[4%dm
endif
if has("autocmd")
if has('gui')
function! <SID>MapExists(name, modes)
for mode in split(a:modes, '\zs')
if !empty(maparg(a:name, mode))
return 1
endif
endfor
return 0
endfunction
autocmd GUIEnter * if !<SID>MapExists("<S-Insert>", "nvso") | execute "map <S-Insert> <MiddleMouse>" | endif
autocmd GUIEnter * if !<SID>MapExists("<S-Insert>", "ic") | execute "map! <S-Insert> <MiddleMouse>" | endif
endif
endif
if filereadable("/etc/papersize")
let s:papersize = matchstr(readfile('/etc/papersize', '', 1), '\p*')
if strlen(s:papersize)
exe "set printoptions+=paper:" . s:papersize
endif
endif
See related question: MatchIt not matching anymore if parenthesis, brackets, etc. are between quotes or in comments?
:set filetype?
. Do you have curly braces in matchpairs?:set matchpairs?
(I'm thinking you do, since%
works...)packadd! matchit
andlet b:match_skip = "0"
in your vimrc? Give me some more time on this one... This question is super interesting, but unfortunately I haven't managed to get enough time on a machine where I can mess up with Vim enough to reproduce and fix this. (Also, for some reason, my setups don't reproduce this and I want to dig into why that is...)~/.vimrc
.matchit
that is not working butmatchparen
.