开发者

Syntax highlight file for the echo command (VIM)?

开发者 https://www.devze.com 2022-12-16 14:00 出处:网络
I am working in a Vim script. One of my functions needs a temporal display like the one you get when typing \":clist\". I don\'t want a whol开发者_如何学JAVAe new buffer since I am so lazy that I pref

I am working in a Vim script. One of my functions needs a temporal display like the one you get when typing ":clist". I don't want a whol开发者_如何学JAVAe new buffer since I am so lazy that I prefer typing just one key to delete the info.

I am stuck with the syntax highlighting of the echo command. I want to apply a whole syntax file but so far I've just seen ":echohl" and with that I can only apply one syntax rule. I've tried a syntax cluster but that does not work either.

Is ":echohl" and syntax clusters the right way to go?


I'm not sure whether you'll manage to do this with echo and the message list.

A good way of going about this would be to create a new buffer and put the stuff you're interested in into that buffer. Then set the buffer to be nomodifiable, nomodified and buftype=wipe. If you need to add more data to the buffer, set modifiable, add the data and then set noma nomod bh=wipe. Set the filetype to something custom and write a syntax file for your required syntax.

Set the buffer name to something specific for your requirements.

Finally, map a keyboard shortcut or command to something like:

map @ :exe 'bufdelete' bufnr('MyBufferName')<CR>

This will make the @ key close the buffer (thereby providing you with a single key method of deleting the info). You could, of course, improve this by sticking it in a function and checking that the buffer exists before deleting it, but I'll leave that as an exercise for you for now (let me know if you have any problems).

An existing plugin that does something fairly similar to this is Dr Chip's RunView plugin. Have a look at the source code and see if it helps. Add a comment to this post if you need any more help.

0

精彩评论

暂无评论...
验证码 换一张
取 消