scippie
scippie

Reputation: 2075

Vim configuration not working across tabs?

This is my .vimrc:

set tabstop=2 softtabstop=0 shiftwidth=2 smarttab
set number
map <F5> :tabp<CR>
map <F6> :tabn<CR>
map <F7> :e %<.cpp<CR>
map <F8> :e %<.h<CR>
map <C-F7> :e %<.vs<CR>
map <C-F8> :e %<.fs<CR>
map <F9> :w<CR>:!./m<CR>
map <F10> :w<CR>:!./%<CR>
let &path.="/home/dirk/projects/dirk/common,/home/dirk/projects/dirk/sp33d,./proj/tmp,./shaders,"
au BufRead *.fs set ft=
au BufRead *.vs set ft=

" Show tabs in light color
hi GroupTabs ctermfg=lightgray
match GroupTabs /\t/
set listchars=tab:>-
set list

My post is about the "Show tabs in light color" part. When I open a file with vim, it does this graying out of the tabs correctly.

However, I like to use multiple tabs, so when I open extra files with the :tabe command or with the -p parameter when starting vim, the graying out of the tabs only works on the first tab, not on other tabs.

I tried opening the files on the other tabs alone and then it works.

Is there something about tabs I don't know? Is there a way to make the graying work on the other tabs as well?

The files I usually work on are cpp, h, py, lua, html, css, ..., they all have this issue, so I guess it has nothing to do with file type specific syntax highlighting?

Any help is appreciated.

Upvotes: 1

Views: 309

Answers (1)

romainl
romainl

Reputation: 196826

Is there something about tabs I don't know?

At least two things:

  1. they are not "tabs" but "tab pages",
  2. your problem is not related to tab pages.

Is there a way to make the graying work on the other tabs as well?

The very first sentence of :help :match is:

Define a pattern to highlight in the current window.

which means that your :match command only impacts the current window and won't have any effect on other windows. Since :tabedit and friends create new windows there's no reason whatsoever to expect your :match to work there too.

For custom matches to work across windows, you need to use :help matchadd() in an autocommand:

augroup CustomMatches
    autocmd!
    autocmd winEnter,BufEnter * call clearmatches() | call matchadd('GroupTabs', '\t', 100)
augroup END

But…

Vim already has an highlight group for those leading tabs:

hi SpecialKey ctermfg=lightgray

so there's no need for any of that in the first place.

Upvotes: 4

Related Questions