I have a mapping that I use to print the highlighting on a line. I got the idea from other posters here so thanks for that. Here’s what I do:
function! PrintSyntaxItem()
let l:colorsyntax = synIDattr(synID(line("."), col("."), 0), "name")
execute "highlight" l:colorsyntax
endfunction
and I map it like this:
nnoremap <A-s> :call PrintSyntaxItem()<CR>
However when I execute it, I get the command line echoed as well as the output that I want which leads to getting a “Press ENTER” prompt. I.e. in the output I see:
:execute "highlight" synIDattr(synID(line("."), col("."), 0), "name")
vimBracket xxx links to Delimiter
Press ENTER or type command to continue
I’d like to lose the :execute line and then the Press ENTER line would go away as well. Is there any way to do this? If I put silent in front of the execute I still get that line printed out but lose the highlight output (as well as the Press ENTER prompt), but then to get back my desired output I just prefix it with unsilent and I get it but…
Basically I want to either suppress the echo of the :execute line or clear it after the fact but I’m not sure how to do either and trawling the docs for info on manipulating the messages hasn’t borne any fruit.
Thanks.
The press enter prompt comes up because the output of
highlighttakes up multiple lines. You could get rid of the extra line by redirecting the output, removing\n, and then echoing it:However, the
xxxsample is no longer properly highlighted. Instead, you can hack the press enter prompt away by temporarily changingcmdheight:This prevents the prompt from being printed in the first place by initially changing the command line height to 2, and then reverting it to 1 afterward in order to cut off the empty line. I did away with the function altogether, but you can of course call it between the
set chif you prefer.