4

I am trying to add bold comments to my vim files. What i mean, is to be able to get something like this:

enter image description here

I saw other articles like this that allow to toggle bold comment.

The proposed solutions from those articles act as follows: when i toggle the function, ALL comments we be bold, or ALL comments we be normal. So that looks like:

enter image description here

However, i am trying to only make certain parts of comment bold, like in the first image.

How to i do this?

Edit: Thanks to the help of @klaus, a possible solution is to do:

sy match myBoldComment '-\+\s\+[^-]*\s\+-\+' | hi myBoldComment cterm=bold gui=bold

Obviously, the pattern is up to you :)

9
  • 3
    That's a vimscript specialty (sort of): take a look at $VIMRUNTIME/syntax/vim.vim and :g/vimCommentTitle
    – D. Ben Knoble
    Jun 16 at 18:08
  • 1
    @needle, check :h :hilight. It will explain how the code is highlighted in vim. Then check the file Ben mentioned, vim.vim. There is a highlight-group called vimCommentTitle, which is made into a reference of another highlight group called PreProc. So, if you want your vim comments to have their titles in bold, you have to do :hi Preproc cterm=bold, gui=bold. Report back if it works or not. Mind you, it's only gonna work with comments in filetype vim (I think).
    – klaus
    Jun 19 at 12:01
  • 1
    I remember seeing some config from a vim-guru so old I cannot even remember his name. He had a function to highlight the visually selected text in different color. I'm sure you could modify that function to embolden the selected text instead of highlighting it. But I cannot remember the guy's name. Sorry.
    – klaus
    Jun 19 at 15:44
  • @needle, about the spacing issue: it's how the syntax is defined in vim.vim syntax file. You could find the line where that syntax is declared (starts with syn match vimCommentTitle) and see where in the regexp is a colon. Try adding a zero-or-many space before that colon (turn : into \s*:) and see if it works. You might need sudoedit if the file is readonly.
    – klaus
    Jun 19 at 15:49
  • 1
    Should be something like -\+\s\+[^-]*\s\+-\+. If you know regexp in other languages, I think you can decode that pattern. Try playing with it until it fits your exact need. But I would try and understand vim's default syntax pattern for commentTitle and add to it instead of totally redefining it.
    – klaus
    Jun 19 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.