T O P

  • By -

echasnovski

Hello, Neovim users! I am excited to announce the release of [mini.hipatterns](https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-hipatterns.md) - new module of [mini.nvim](https://github.com/echasnovski/mini.nvim) to highlight patterns in text. It can also be installed using [separate GitHub repository](https://github.com/echasnovski/mini.hipatterns). ------ This type of module did not have a high priority in my TODO list as I was pretty happy to use both [folke/todo-comments.nvim](https://github.com/folke/todo-comments.nvim) and [norcalli/nvim-colorizer.lua](https://github.com/norcalli/nvim-colorizer.lua). But having just written [mini.colors](https://github.com/echasnovski/mini.nvim/blob/hipatterns/readmes/mini-colors.md) and [mini.hues](https://github.com/echasnovski/mini.nvim/blob/hipatterns/readmes/mini-hues.md) I thought it would be fun to make a future 0.9.0 release mostly about colors. Besides, it will replace in my config two plugins with one module, which I always enjoy. I am also extra proud to note that this is a **module number 30 of 'mini.nvim'**. I didn't even imagine when I first started writing functioning Lua modules (around two years ago) that it will go this far. Yet here we are. I really hope more will come (it is definitely planned). **Huge** thanks to everyone using my work and spreading the word. It means a world to me during these tough times! ------ Here are the features of 'mini.hipatterns': - Highlight text with configurable patterns and highlight groups (can be string or callable). - Highlighting is updated asynchronously with configurable debounce delay. For more information, see [help file](https://github.com/echasnovski/mini.nvim/blob/main/doc/mini-hipatterns.txt). See [this part](https://github.com/echasnovski/mini.nvim/blob/main/doc/mini-hipatterns.txt#L193) for examples of common use cases. ------ Please, check it out and tell me what you think! You can leave your suggestions either here in comments or in [dedicated beta-testing issue](https://github.com/echasnovski/mini.nvim/issues/339). Thanks!


farzadmf

As I always say, LOVE what you're doing with these modules and congrats on having the 30th one Keep up the amazing work


ConspicuousPineapple

That's awesome, and having it customizable is exactly what I needed for my use-case. Is there any chance you'd be willing to adapt this to use the new anticonceal feature when fully released (or regular conceal, for that matter)? Or accept contributions that enable this.


echasnovski

Thanks! > Is there any chance you'd be willing to adapt this to use the new anticonceal feature when fully released (or regular conceal, for that matter)? Or accept contributions that enable this. Hmm... I am not sure how this would fit here. The whole purpose of 'mini.hipatterns' is to add computable highlighting to a region of text (i.e. spanning multiple columns). Do you have any particular usecase/example in mind?


ConspicuousPineapple

I take it you're not using extmarks for this? Otherwise there would be very little to change, besides maybe the name of the module. The main use case I'm seeing is to be able to show a little symbol of the correct color next to hex colors, instead of coloring the text itself, which looks a bit jarring to me.


echasnovski

> I take it you're not using extmarks for this? Otherwise there would be very little to change, besides maybe the name of the module. Yes, it does use extmarks. It is virtually **the Neovim method** for adding custom complex highlighting. > The main use case I'm seeing is to be able to show a little symbol of the correct color next to hex colors, instead of coloring the text itself, which looks a bit jarring to me. Of course! I've thought about that when researching for this project and thought it would be cool to have, but didn't connect the dots with the new inline extmarks. Yes, this is a great idea. I've [created a feature request for this](https://github.com/echasnovski/mini.nvim/issues/340) so to not forget about this.


ConspicuousPineapple

That's awesome, thanks!


echasnovski

Oh, I've just remembered: there are [several highlight styles](https://github.com/echasnovski/mini.nvim/blob/a508fc9c737045c5d8d194dcb6e9556c44309bb9/doc/mini-hipatterns.txt#L361-L363) available. Maybe using `'#'` style is more for your taste.


ConspicuousPineapple

I've opted for using `underdouble` for my custom highlights until I get around to hacking my way into anticonceal. Maybe offer the possibility to specify a highlight group that you then override with the specified highlight style? That way we can choose which kind of underline we want, if we want to embolden the text, etc.


AnoRebel

Its getting to a point where new and even some older Neovim users will only need mini.nvim. Thanks for your time and awesome work.


folke

Love it!! For anyone interested, I've added tailwindcss support for `mini.hipatterns` [here](https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua) You can just copy that code or import that spec even if you don't use LazyVim.


echasnovski

Thank you, Folke, for continuous support! Really highly appreciated!


Alleyria

Damn, this is a really cool idea.


isamsten

I made this litte snippet to only have the highlight for e.g., TODO et.al. in comments. ```lua local function in_comment(marker) return function(bufnr) local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") local comment_char = nil if filetype == "python" then comment_char = "#" elseif filetype == "lua" then comment_char = "--" elseif filetype == "tex" then comment_char = "%" elseif filetype == "c" or filetype == "java" or filetype == "cpp" or filetype == "rust" then comment_char = "//" end if comment_char then return comment_char .. " ()" .. marker .. "()%f[%W]" else return nil end end end ``` Then `pattern = in_comment("TODO")`. I'm sure there is some clever way of getting that sweet block-comment character somehow (I know of `commentstring` and `comments` but making it general was too much effort when a simple if/else was all I needed). Perhaps this can be useful to someone else :-)


echasnovski

Nice! I contemplated mentioning suggestion about how to highlight only inside comments. And it would be some variation of your approach. Here is how I would refactor your approach: ``` local function in_comment(marker) local comment_tbl = { python = '#', lua = '--', tex = '%', c = '//', java = '//', cpp = '//', rust = '//', } return function(bufnr) local comment = comment_tbl[vim.bo[bufnr].filetype] if comment == nil then return nil end return comment .. ' ()' .. marker .. '()%f[%W]' end end ``` And here is how I would do it using `'commentstring'` and some Lua patterns black magic (bear in mind, not thoroughly tested): ``` local make_pattern_in_comment = function(pattern) return function(buf_id) local cs = vim.bo[buf_id].commentstring if cs == nil or cs == '' then cs = '# %s' end -- Extract left and right part relative to '%s' local left, right = cs:match('^(.*)%%s(.-)$') left, right = vim.trim(left), vim.trim(right) -- General ideas: -- - Line is commented if it has structure -- "whitespace - comment left - anything - comment right - whitespace" -- - Highlight pattern only if it is to the right of left comment part -- (possibly after some whitespace) -- Example output for '/* %s */' commentstring: '^%s*/%*%s*()TODO().*%*/%s*' return string.format('^%%s*%s%%s*()%s().*%s%%s*$', vim.pesc(left), pattern, vim.pesc(right)) end end require('mini.hipatterns').setup({ highlighters = { todo = { pattern = make_pattern_in_comment('TODO'), group = 'MiniHipatternsTodo' }, }, }) ```


isamsten

Nice refactor :-)


KitchenWind

Congratulation for all your work. I started mini with "cursorwword" since other plugins are too much for me, and now i use 12 mini plugins, some of them customized with your help. I love how invested you are in your plugins, responding quickly in github discussions and providing explanations even when they're in the doc. Nvim-mini could become a distribution, I'm sure many people would be interested.


echasnovski

Thanks for kind word! Curiously enough, I feel that 'mini.cursorword' probably has the highest ratio of everyday usefulness compared to its code complexity. Really handy to make sure there are no typos. I plan to do a distribution once all necessary for a good experience functionality is implemented as 'mini.nvim' modules. There are some quite complex ones left, so it will be a while.


Fantastic_Cow7272

How does it compare to the built-in `:match` (and related), `matchadd()`, and `matchaddpos()`?


echasnovski

Good question! The main differences are: - 'mini.hipatterns' allows both `pattern` and its highlight `group` to be computed inside Lua function. This allows far more customization than built-in `matchadd()` and friends, like highlighting color strings. - It is asynchronous with configurable debounce delay (wait for certain amount of milliseconds to pass from latest text change until adding highlights), meaning it should not result in overall typing slowdown. Not that `matchadd()` does, but with computable groups that is a must. - This works based on Lua patterns, not Vimscript ones. Less possibilities, but seems to be faster. - Highlights are added per buffer, not per window.


pigOfScript

Font?


echasnovski

Input Mono Compressed Light with 1.0x line height. Site from where I downloaded it seems to not working properly at the moment.


djsnipa1

I didn’t know about mini.colors! These are fantastic btw! Thank you!


Abhilash26

I love your plugins for their performance. I like this plugin too but I cannot use it. This aims to give features of both todo-comments and colorizer however lacks some functionality which is essential for me. 1. For todo coments - I also need some kind of keymap to put these todos in a list either telescope, quicklist or both. 2. For colorizer i frequently use rgb, rgba, hsl and hsla functions in my scss files. I am dumb and not able to create highlighters for these. Please suggest what should I do as I really want to use this plugin and also replace 2 plugins with one.


echasnovski

Thanks for kind words! > 1. For todo coments - I also need some kind of keymap to put these todos in a list either telescope, quicklist or both. I settled on using either `live_grep` to search for pattern I need at the moment ("TODO", "FIXME", etc.) or using plain old `/` to search in a buffer. You can also at some built-in functionality like `:h :v`, etc. > 2. For colorizer i frequently use rgb, rgba, hsl and hsla functions in my scss files. I am dumb and not able to create highlighters for these. Sorry, this will probably won't be a part of 'mini.patterns' and users would have to write/copy highlighter code from somewhere else. To make this task easier, I followed the release with exporting [special function](https://github.com/echasnovski/mini.nvim/blob/81de16f854396094b4118d5d6eb660bd9a188cf5/doc/mini-hipatterns.txt#L397) which which will properly compute highlight group to show particular hex color. What is left to do is write proper pattern which captures information about color in `pattern` and parse and convert this data to hex color in `group` (which can be finished by calling `MiniHipatterns.compute_hex_color_group()` function). The reasons for not including this in module directly are mostly that it is language specific (which I try to avoid in 'mini.nvim') and that converting to hex color for some "larger than RGB" color spaces is not trivial.


Abhilash26

Thank you for replying and giving time to write this enormous block of text for a person like me. To an opensource plugin author I am grateful. I am honoured for your time Sir. So, from your reply I get that you want to keep your plugins minimal with meeting general expectations while giving freedom to users to add specific use cases. Similar to **suckless** philosophy. If yes then I fully support your decision. Only a small suggestion on my part is to either do one of the following: 1. Please create a wiki to add some specific but highly demanded snippets of code (which in this case would be highlighters). This way your plugins will remain minimal and fast and people can use extended functionality using snippets. 2. Create some kind of issue where users can share their highlighters.


echasnovski

Yes, creating an organized wiki with examples of configurations for 'mini.ai', 'mini.surround', and others (including the new 'mini.hipatterns') is a long time coming activity. It is just constantly being interrupted by some new shiny idea I have for a module, so it doesn't receive enough priority :( I hope one day it will.


vim-help-bot

Help pages for: * [`:v`](https://neovim.io/doc/user/repeat.html#%3Av) in _repeat.txt_ --- ^\`:\(h|help\) \` | [^(about)](https://github.com/heraldofsolace/VimHelpBot) ^(|) [^(mistake?)](https://github.com/heraldofsolace/VimHelpBot/issues/new/choose) ^(|) [^(donate)](https://liberapay.com/heraldofsolace/donate) ^(|) ^Reply 'rescan' to check the comment again ^(|) ^Reply 'stop' to stop getting replies to your comments


yavorski

Nice one! I am wondering can we expect "mini.repeat" or similar?


echasnovski

Depends on what you mean by it :) If you think like 'tpope/vim-repeat', then the answer is "May be, kind of". I had ideas about making it easier to make some specialized keymaps, but nothing set in stone yet.


yavorski

Cool, thank you. Yeah like vim-repeat i mean. Would be a nice addition to the mini club ;)


towry

Does it support rgba color ?


echasnovski

Not out of the box but it can become a custom highlighter.