andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.
https://www.vim.org/scripts/script.php?script_id=5624
MIT License
1.7k stars 71 forks source link

Any way to have tags highlighted including both < and >, or not have it highlighted at all? #98

Open oblitum opened 4 years ago

oblitum commented 4 years ago

Current tag matching doesn't highlight initial <, so for <foo>, I have < not highlighted and foo> highlighted, same applies for closing tag.

Is there any way to change this behavior? I really don't like it because it looks like a visual bug to me, I wished whole <foo> to be highlighted, or just the tag contents foo.

If my cursor is just at < or >, then it would just highlight < and >, but if it's inside, then it would be as requested, whole or just contents.


Not a must for me but I just want to make a note that let g:matchup_matchpref = {'html': {'tagnameonly': 1}} for XML files didn't work for me, only for HTML files, but it doesn't help much even if it worked on XML because I noticed on HTML file that the closing tags have the > highlighted, which is what I don't want.

andymass commented 4 years ago

So you want the < to be highlighted but not an active cursor location? In other words when using `% the cursor does not land there? I don't know if there's an example of this- generally the start of a match must be in a unique position in the buffer and is where the cursor lands on.

Assuming it could be implemented, is it possible that would be confusing to the user?


 let g:matchup_matchpref = {'xml': {'tagnameonly': 1}}
                             ^^^
oblitum commented 4 years ago

Actually I didn't thought at all yet regarding cursor jumping, only highlighting, so bear with me that whatever is the behavior on that should just be still the same.

To illustrate it better, in LaTeX files I have what I prefer, but kinda reversed form. Given a \begin{foo}, \end{foo} pair, if my cursor is at any char in \begin or \end, the whole tags are highlighted, then if my cursor goes to { or }, then just the braces are highlighted instead, despite it being part of the tag. I don't get the same with markup language, the tags are being highlighted partially when cursor isn't over an inner (<, >, is on the edge, but still inner) brace/bracket, and when moving to the brace/bracket that's inner to the tag, they're highlighted as expected.


Ah OK thanks, I interpreted conf incorrectly when reading docs, I thought that by setting html there all markup languages would follow.

andymass commented 4 years ago

Good point, it does work pretty well for latex. Technically speaking the main difference is the cursor is in a different location in latex, but in the same location as another match in html so the engine gets confused. I suppose this could be fixed (e.g., by just visually adjust the highlighting by one), but I'm not sure.

Would it be enough of a work-around if the tagnameonly option just didn't highlight any of the </>? Actually, I don't know why it does in the first place, and can change this pretty easily.

oblitum commented 4 years ago

Would it be enough of a work-around if the tagnameonly option just didn't highlight any of the </>? Actually, I don't know why it does in the first place, and can change this pretty easily.

It would help, but I wished I could set the option for all markup at once without having to list filetypes. It would not be my preference though, I'd just use it because the default isn't highlighting as I expect (all this is because lack of symmetry annoys my brain).

andymass commented 4 years ago

I made the first change, which I think makes sense. Leaving the issue open for your more difficult ask.

I'll just point out that the highlighting now matches that of the other most popular highlight-tag plugins (as well as notepad++ incidentally):

https://github.com/Valloric/MatchTagAlways https://github.com/gregsexton/MatchTag https://stackoverflow.com/questions/8168320/can-vim-highlight-matching-html-tags-like-notepad

It doesn't mean we can't do it better, but this is evidence to me that it's what a large number of users expect or are accustomed to. Please let me know if you have examples of the alternative or a better way.

for all markup at once without having to list filetypes

Sure, I could add such an option, but do you have a list of markup filetypes? vim doesn't really have a concept of this.. and do you include markdown, jsx, etc? My fear is if I add an option for "all markdown types" somebody will ask later for an option which specifies which types are markdown or an option to turn it off for a specific type.

oblitum commented 4 years ago

Sure, I could add such an option, but do you have a list of markup filetypes? vim doesn't really have a concept of this..

It's not much a concept of vim actually but more a concept of matchup, tbh I didn't want to have filetypes involved in this at all, all I wanted is to control the behavior of matchup when it's highlighting these kind of tags, so that it doesn't do wrong highlighting. The filetype list is a circumvention solution, at there's no flag to control that behavior directly regardless of the filetype.

oblitum commented 4 years ago

b3bda15 worked on HTML, but didn't on XML. Configuration:

let g:matchup_matchpref = {
\   'html': {'tagnameonly': 1},
\   'xml': {'tagnameonly': 1}
\ }
andymass commented 3 years ago

I am still considering adding a good built-in tag matching regex because the most issues I get are around these kinds of files. However, I do feel that it should be user opt-in. We still need a list of applicable file types because otherwise it will be too expensive to run over every buffer.

Documenting list of file types with html-like tags: vim built-in: typescriptreact, javascriptreact, xml, html, markdown external: tsx, jsx (same as the above?), vue