Vi and Vim Asked by Vjekoslav on August 31, 2021
I’ve put following code in my vimrc.
function ExtraHighlights()
let list = taglist('.*')
for item in list
if item.kind == 's' || item.kind == 't' || item.kind == 'u' || item.kind == 'g'
exec 'syntax keyword TagType '.item.name
elseif item.kind == 'f'
exec 'syntax keyword TagFunction '.item.name
elseif item.kind == 'd' || item.kind == 'e'
exec 'syntax keyword TagDefine '.item.name
endif
endfor
endfunction
nnoremap <silent> <C-h> :call ExtraHighlights()<CR>
It basically generates new syntax keywords for the current buffer based on tags collected by ctags
. I pick up those keywords in my color theme. If I generate keywords for buffer A, then open another buffer B in the same window and then come back to original buffer A, the keywords are gone and I need to regenerate them.
Is there a way to make it permanent for the current vim session? I tried to call this function from BufEnter
autocmd, but it’s too slow…
If I generate keywords for buffer A, then open another buffer B in the same window and then come back to original buffer A, keywords are gone and I need to regenerate them
Actually the problem is not that you switched from the buffer A, but is that the buffer A was unloaded by Vim. And upon unloading buffer contents Vim also disposes its syntax elements (and many other things).
So all you have to do is to keep your buffer loaded in memory even after its last window is closed (or occupied by another buffer). Whether you choose setlocal bufhidden=hide
or setglobal hidden
doesn't matter.
Correct answer by Matt on August 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP